home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / amok98-106 / amok101 / muchmore / src / muchmore.mod next >
Text File  |  1994-01-31  |  97KB  |  2,948 lines

  1. (*---------------------------------------------------------------------------
  2. :Program.    MuchMore.mod
  3. :Author.     Fridtjof Siebert
  4. :Address.    Nobileweg 67, D-70439 Stuttgart, Germany
  5. :Shortcut.   [fbs]
  6. :Copyright.  Freeware
  7. :Language.   Oberon-2
  8. :Translator. Amiga Oberon Compiler v3.01
  9. :History.   V1.0 summer-88: First very slow internal version             [fbs]
  10. :History.   V1.1 24-Sep-88: First published version                      [fbs]
  11. :History.   V1.2 26-Nov-88: Now displays Filelength & Percentage         [fbs]
  12. :History.        27-Nov-88: Mouse can be used instead of Space/BackSpace [fbs]
  13. :History.   V1.3 29-Apr-89: Strong increase in speed, removed WarpText   [fbs]
  14. :History.        29-Apr-89: Now supports Numeric Keys (Home,PgUp etc.)   [fbs]
  15. :History.        29-Apr-89: Now opens Screen as big as gfx.normalDisplay [fbs]
  16. :History.   V1.4 29/30-Apr-89: Asynchronus loading/displaying. Very nice [fbs]
  17. :History.        30-Apr-89, 00:33: Removed bugs in Filelength & L-Command[fbs]
  18. :History.        30-Apr-89, 02:21: Added Find-Command                    [fbs]
  19. :History.        30-Apr-89, 10:30: Scrolling stops when window inactive  [fbs]
  20. :History.        01-May-89: Allocates no more unneeded memory for text   [fbs]
  21. :History.        07-May-89: Allocates even less memory now               [fbs]
  22. :History.        14-May-89: Removed deadlock-bug with Find-Window        [fbs]
  23. :History.   V1.5 25-May-89: Added print feature                          [fbs]
  24. :History.        25-May-89: Removed all imports (apart from Arts)        [fbs]
  25. :History.        26-May-89: inspired by J. Kupfer, I added nk 5 to quit  [fbs]
  26. :History.        26-May-89: Now handle BS correctly                      [fbs]
  27. :History.   V1.6 02-Jul-89: Now supports several fontstyles and colors   [fbs]
  28. :History.   V1.7 03-Jul-89: Is again as fast as it was with 2 colors     [fbs]
  29. :History.        03-Jul-89: Now no more crashes when quitting while print[fbs]
  30. :History.        07-Jul-89: removed bug with texts of length 0           [fbs]
  31. :History.   V1.8 10-Jul-89: small bug in find-command removed            [fbs]
  32. :History.        10-Jul-89: now found strings are highlighted            [fbs]
  33. :History.        14-Jul-89: nk0 to display fileinfo                      [fbs]
  34. :History.   V2.0 06-Aug-89: Ported this to OBERON                        [fbs]
  35. :History.        06-Aug-89: Added ARP-FileRequester                      [fbs]
  36. :History.        07-Aug-89: Added L - (load new file) Command            [fbs]
  37. :History.   V2.1 03-Sep-89: no more gurus if an r/w error occures        [fbs]
  38. :History.        03-Sep-89: MM used to execute CSI-Codes backwards. fixed[fbs]
  39. :History.        03-Sep-89: ping / pong with Shift+Fn / Fn               [fbs]
  40. :History.        03-Sep-89: new command: goto                            [fbs]
  41. :History.   V2.2 05-Sep-89: will run with any keymapping now             [fbs]
  42. :History.   V2.3 17-Sep-89: New command: sleep & Pop-Up feature          [fbs]
  43. :History.        17-Sep-89: "MuchMore -s" will go to sleep immediately   [fbs]
  44. :History.        17-Sep-89: Interprets <CSI>m as <CSI>0m now             [fbs]
  45. :History.   V2.4 17-Sep-89: New command: write block "w"                 [fbs]
  46. :History.        17-Sep-89: rewritten argument parser to allow quotes    [fbs]
  47. :History.   V2.5 18-Sep-89: now uses the 8x8 font set with SetFont       [fbs]
  48. :History.        19-Sep-89: no more scatters memory. Allocates 4K Chunks [fbs]
  49. :History.   V2.6 26-Jun-90: Made MuchMore reentrant                      [fbs]
  50. :History.        26-Jun-90: Opens 1-Plane Screen if memory is rare       [fbs]
  51. :History.        26-Jun-90: Asynchronus fast scrolling with Ctrl-Up/Down [fbs]
  52. :History.        26-Jun-90: Now supports interlaced screens              [fbs]
  53. :History.        08-Aug-90: CLI-Option '-l' to toggle interlaced mode    [fbs]
  54. :History.   V2.7 09-Aug-90: no more RethinkDisplay()s,looks good with 2.0[fbs]
  55. :History.        10-Aug-90: Supports Kick2.0 ASL-FileRequester           [fbs]
  56. :History.   V2.8 26-Dez-90: Leaves space between lines on interl. scrns  [fbs]
  57. :History.   V3.0 04-Jul-91: Supports any non-proportional font now       [fbs]
  58. :History.        04-Jul-91: no more supports '-s' (sleep),was rarely used[fbs]
  59. :History.        04-Jul-91: new Options -f<font> and -s<size> for font   [fbs]
  60. :History.        09-Nov-91: Find works w/ dmouse(window may get inactive)[fbs]
  61. :History.   V3.1 04-Sep-92: Uses Screenmode of Workbench screen          [fbs]
  62. :History.   V3.2 02-Nov-92: Supports non-scrollable screens              [fbs]
  63. :History.        02-Nov-92: Complete redraw doesn't scroll anymore       [fbs]
  64. :History. V3.2.1 24-Dec-92: XPK Support                             (C.Stiens)
  65. :History.        24-Dec-92: New option -p for Password              (C.Stiens)
  66. :History.        24-Dec-92: New option -e for Extra Spacing         (C.Stiens)
  67. :History.        24-Dec-92: New option -c for Screen Colors         (C.Stiens)
  68. :History.        24-Dec-92: Tooltypes                               (C.Stiens)
  69. :History. V3.2.2 08-Jan-93: Doesn't use MyMakeScreen() no more      (C.Stiens)
  70. :History. V3.2.3 08-Feb-93: Now closes Console Device               (C.Stiens)
  71. :History.        08-Feb-93: Non-Scroll Mode didn't work always      (C.Stiens)
  72. :History.        10-Feb-93: ScreenMode Requester                    (C.Stiens)
  73. :History.        10-Feb-93: New Option -s for Scroll Mode           (C.Stiens)
  74. :History.        10-Feb-93: Busy Pointer                            (C.Stiens)
  75. :History.        14-Feb-93: Now evals Tooltypes also on CLI start   (C.Stiens)
  76. :History. V3.2.4 15-Feb-93: Clears Idcmp while Busy                 (C.Stiens)
  77. :History.        15-Feb-93: Bugs in GetString fixed                 (C.Stiens)
  78. :History.        19-Feb-93: More Scrollmodes                        (C.Stiens)
  79. :History.        20-Feb-93: Bug in Type() fixed                     (C.Stiens)
  80. :History. V3.2.5 08-Mar-93: Asynch Scrolling changed                (C.Stiens)
  81. :History.        08-Mar-93: New Option -t for Taskpri               (C.Stiens)
  82. :History.        10-Mar-93: Now uses Dos.ReadArgs if KS 2.04        (C.Stiens)
  83. :History. V3.2.6 19-Mar-93: scrollmode 3 now also scrolls soft      (C.Stiens)
  84. :History.        19-Mar-93: New Option -o for one plane             (C.Stiens)
  85. :History.        19-Mar-93: New Option -a for tab width             (C.Stiens)
  86. :History.        19-Mar-93: Removed QText                           (C.Stiens)
  87. :History.        21-Mar-93: Opens screen with full overscan width   (C.Stiens)
  88. :History.        22-Mar-93: Filename can be on any pos at KS1.3     (C.Stiens)
  89. :History.        27-Mar-93: New Option N=NOOSCAN                    (C.Stiens)
  90. :History. V3.2.7 07-Apr-93: Dont pokes to bitmap no more            (C.Stiens)
  91. :History. V3.2.8 12-Apr-93: New Option B=PLANES                     (C.Stiens)
  92. :History. V3.2.9 12-May-93: Implemented V36 ANSI Codes              (C.Stiens)
  93. :History. 3.2.10 16-May-93: Locale Support                          (C.Stiens)
  94. :History.        16-May-93: DispMode-Requester font-sensitive       (C.Stiens)
  95. :History.   V3.3 21-Jun-93: Code optimised                          (C.Stiens)
  96. :History.        25-Jun-93: Safe quit                               (C.Stiens)
  97. :History.   V3.4 29-Jun-93: Clipboard support                       (C.Stiens)
  98. :History.        29-Jun-93: took version number out of catalog      (C.Stiens)
  99. :History.   V3.5 31-Jul-93: case sensitive search, Boyer-Moore Alg. (C.Stiens)
  100. :History.   V3.6 15-Aug-93: Page up/down with softscroll reimpl.    (C.Stiens)
  101. :History.        16-Aug-93: Flash at EOF/BOF                        (C.Stiens)
  102. :History.   V3.7 28-Oct-93: New option E=EDITOR                     (C.Stiens)
  103. :History.        21-Nov-93: MM was not 100% pure (BusyPointer)      (C.Stiens)
  104. :History.        21-Nov-93: Password has to be entered in stringgad (C.Stiens)
  105. :History.   V4.0 07-Dec-93: MM can run in a WB Window               (C.Stiens)
  106. :History.        07-Dec-93: Options WINDOW, LEFT, TOP, WIDTH, HEIGHT(C.Stiens)
  107. :History.        07-Dec-93: Kick 1.3 is no more supported           (C.Stiens)
  108. :History.        07-Dec-93: Removed Options SCROLLMODE and NOOSCAN  (C.Stiens)
  109. :History.   V4.1 05-Jan-94: Prefs BusyPointer, set rp.mask or MaxPen(C.Stiens)
  110. :History.        10-Jan-94: Pipe Support, new option PUBSCREEN      (C.Stiens)
  111. :History.        12-Jan-94: Option SCROLLMODE reintroduced          (C.Stiens)
  112. :History.        12-Jan-94: New Option I=INTERLEAVED                (C.Stiens)
  113. :History.   V4.2 29-Jan-94: Zoom Gadget (v39)                       (C.Stiens)
  114. :History.        29-Jan-94: Better test for Pipe                    (C.Stiens)
  115. :History.        30-Jan-94: Icon is found if MM is started w/path   (C.Stiens)
  116. :History.        31-Jan-94: New option FASTQUIT                     (C.Stiens)
  117. :History.        31-Jan-94: ShowTask allocates his signals now      (C.Stiens)
  118. :Contents.   A Soft-Scrolling ASCII-File Viewer.
  119. :Remark.     Compile: 'Oberon -svbcrntzdma MuchMore' for short code
  120. :Remark.     Compile: 'Oberon -dma MuchMore' for safe code
  121. :Remark.     Link:    'OLink -dma MuchMore'
  122. ---------------------------------------------------------------------------*)
  123.  
  124. MODULE MuchMore; (* $StackChk- *)
  125.  
  126. IMPORT gt := GadTools,
  127.        loc:= Locale,
  128.        ip := IFFParse,
  129.        u  := Utility,
  130.        con:= Console,
  131.        str:= Strings,
  132.        ie := InputEvent,
  133.        I  := Intuition,
  134.        g  := Graphics,
  135.        d  := Dos,
  136.        e  := Exec,
  137.        ol := OberonLib,
  138. (* $IF quiet *) NoRequesters, (* $END *)
  139.        SYS:= SYSTEM;
  140.  
  141. CONST
  142.   MuchText = "MuchMore 4.2 © 1988-94 AMOK\o$VER: muchmore 4.2 (31.1.94)";
  143.   Version = "v4.2";
  144.  
  145.   MSGOOM        = 0;
  146.   MSGCOS        = 1;
  147.   MSGCOW        = 2;
  148.   MSGCOF        = 3;
  149.   MSGRWERR      = 4;
  150.   MSGRETRYABORT = 5;
  151.   MSGEMPTY      = 6;
  152.   MSGSAVE       = 7;
  153.   MSGUSE        = 8;
  154.   MSGCANCEL     = 9;
  155.   MSGOK         = 10;
  156.   MSGCHOOSESM   = 11;
  157.   MSGINFOFMT    = 12;
  158.   MSGH1         = 13;
  159.   MSGH2         = 14;
  160.   MSGH3         = 15;
  161.   MSGH4         = 16;
  162.   MSGH5         = 17;
  163.   MSGH6         = 18;
  164.   MSGH7         = 19;
  165.   MSGH8         = 20;
  166.   MSGH9         = 21;
  167.   MSGH10        = 22;
  168.   MSGH11        = 23;
  169.   MSGH12        = 24;
  170.   MSGH13        = 25;
  171.   MSGH14        = 26;
  172.   MSGH15        = 27;
  173.   MSGH16        = 28;
  174.   MSGH17        = 29;
  175.   MSGH18        = 30;
  176.   MSGH19        = 31;
  177.   MSGH20        = 32;
  178.   MSGH21        = 33;
  179.   MSGH22        = 34;
  180.   MSGH23        = 35;
  181.   MSGH24        = 36;
  182.  
  183.  
  184.   TYPE
  185.     MSGTYPE = ARRAY 37 OF e.STRPTR;
  186.  
  187.   CONST
  188.  
  189.     MSGS = MSGTYPE(
  190.       SYS.ADR( "Out of memory"      ),
  191.       SYS.ADR( "Can't open screen"  ),
  192.       SYS.ADR( "Can't open window"  ),
  193.       SYS.ADR( "Can't open file"    ),
  194.       SYS.ADR( "Read/Write Error"   ),
  195.       SYS.ADR( "Retry|Abort"        ),
  196.       SYS.ADR( "File empty"         ),
  197.       SYS.ADR( "Save"               ),
  198.       SYS.ADR( "Use"                ),
  199.       SYS.ADR( "Cancel"             ),
  200.       SYS.ADR( " OK "               ),
  201.       SYS.ADR( "Choose Screen Mode:"),
  202.       SYS.ADR( " File: %-30.30s %ld%% (%ld of %ld Bytes) %ld Lines"),
  203.       SYS.ADR( "\x13                \x15  MuchMore %s Commands:  "),
  204.       SYS.ADR( " \x0dSpace\x05,\x0d LMB\x05:         Start / Stop scrolling, Quit at end of file"),
  205.       SYS.ADR( " \x0dBackSpace\x05,\x0d RMB\x05:     Start / Stop scrolling backwards"),
  206.       SYS.ADR( " \x0dUp\x05/\x0dDown\x05:            Move one line \x0dup\x05 or \x0ddown\x05"),
  207.       SYS.ADR( " \x0dShift \x05+\x0d Up\x05/\x0dDn\x05:      Start / Stop quick scrolling \x0dup\x05 or \x0ddown\x05"),
  208.       SYS.ADR( " \x0dControl\x05:            Increase scroll speed"),
  209.       SYS.ADR( " \x0dAlt\x05+\x0dUp\x05/\x0dDn\x05,\x0d PgUp\x05/\x0dDn\x05: Move one page \x0dup\x05 or \x0ddown\x05"),
  210.       SYS.ADR( " \x0dT\x05,\x0d Home \x05/\x0d B\x05,\x0d End\x05:   Goto \x0dt\x05op / \x0db\x05ottom of text"),
  211.       SYS.ADR( " (\x0DShift\x05) \x0DF\x05, \x0DN\x05, \x0DP\x05:    \x0DF\x05ind string (case sensitive), \x0DN\x05ext, \x0DP\x05revious"),
  212.       SYS.ADR( " \x0dShift \x05+\x0d Fn\x05:         Set textmarker #n to current position"),
  213.       SYS.ADR( " \x0dFn\x05:                 Goto marker #n or set marker #n if it wasn't set yet"),
  214.       SYS.ADR( " \x0dG\x05:                  \x0dG\x05oto line..."),
  215.       SYS.ADR( " \x0dNK 0\x05:               Display info line"),
  216.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d O\x05:    Print text"),
  217.       SYS.ADR( " \x0dW\x05:                  \x0dW\x05rite block between marker #1 and #2 to file or prt"),
  218.       SYS.ADR( " \x0dL\x05:                  \x0dL\x05oad new text"),
  219.       SYS.ADR( " \x0dHELP\x05,\x0d H\x05:            Show commands"),
  220.       SYS.ADR( " \x0dESC\x05,\x0d Q\x05,\x0d X\x05,\x0d NK 5\x05:\x0d    Q\x05uit"),
  221.       SYS.ADR( "© \x131988-94 Fridtjof Siebert & Christian Stiens"),
  222.       SYS.ADR( ""),
  223.       SYS.ADR( "  \x13Please refer to MuchMore.doc for a detailed copyright notice"),
  224.       SYS.ADR( "  This is another product of the Amiga MODULA & OBERON Klub Stuttgart - \x0d\x13AMOK"),
  225.       SYS.ADR( " \x0dC\x05:                  \x0dC\x05opy block between marker #1 and #2 to clipboard"),
  226.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d E\x05:    \x0dE\x05dit text") );
  227.  
  228.  
  229.  
  230. TYPE BusyPointer = ARRAY 36 OF INTEGER;
  231.  
  232. CONST TheBusyPointer = BusyPointer(
  233.   00000U,00000U,
  234.   00400U,007C0U, 00000U,007C0U, 00100U,00380U, 00000U,007E0U,
  235.   007C0U,01FF8U, 01FF0U,03FECU, 03FF8U,07FDEU, 03FF8U,07FBEU,
  236.   07FFCU,0FF7FU, 07EFCU,0FFFFU, 07FFCU,0FFFFU, 03FF8U,07FFEU,
  237.   03FF8U,07FFEU, 01FF0U,03FFCU, 007C0U,01FF8U, 00000U,007E0U,
  238.   00000U,00000U);
  239.  
  240.  
  241. CONST (* RawKey Codes: *)
  242.  
  243.   ESC   = 45H; HELP  = 5FH;
  244.   UP    = 4CH; DOWN  = 4DH;
  245.   SPACE = 40H; BS    = 41H;
  246.   CR    = 44H; ENTER = 43H;
  247.   NK0   = 0FH; NK1   = 1DH; NK2   = 1EH; NK3   = 1FH;
  248.   NK5   = 2EH; NK7   = 3DH; NK8   = 3EH; NK9   = 3FH;
  249.   F1    = 50H; F10   = 59H;
  250.  
  251.  
  252. CONST
  253.   ShowStackSize = 4096;
  254.   BufferSize = 2048;
  255.  
  256.   w = TRUE;
  257.   f = FALSE;
  258.  
  259.   MyIdcmp = LONGSET{I.rawKey,I.mouseButtons,I.closeWindow,I.activeWindow,I.inactiveWindow,I.newSize};
  260.  
  261. (* Control codes: *)
  262.   plain    = 11X;
  263.   italic   = 12X;
  264.   bold     = 13X;
  265.   boldit   = 14X;
  266.   ulineon  = 15X;
  267.   ulineoff = 16X;
  268.  
  269.   Italic = 0;
  270.   Bold   = 1;
  271.   Ulin   = 2;
  272.   Inv    = 3;
  273.  
  274. TYPE
  275.   String    = e.STRING;
  276.   StringPtr = e.STRPTR;
  277.   CharPtr   = UNTRACED POINTER TO CHAR;
  278.   LongPtr   = UNTRACED POINTER TO LONGINT;
  279.  
  280.   TextLinePtr = UNTRACED POINTER TO TextLine;
  281.   TextLine = STRUCT
  282.                prev : TextLinePtr;
  283.                next : TextLinePtr;
  284.                len  : INTEGER;
  285.                size : INTEGER;
  286.                text : String;
  287.              END;
  288.  
  289. CONST
  290.   MaxLen = SIZE(String);
  291.  
  292. TYPE
  293.  
  294.   WBStartupPtr = UNTRACED POINTER TO STRUCT (message : e.Message)
  295.                    process    : d.ProcessId;
  296.                    segment    : e.BPTR;
  297.                    numArgs    : LONGINT;
  298.                    toolWindow : StringPtr;
  299.                    argList : UNTRACED POINTER TO ARRAY 256 OF STRUCT
  300.                                  lock : d.FileLockPtr;
  301.                                  name : StringPtr;
  302.                              END;
  303.                  END;
  304.  
  305.   DiskObjectPtr = UNTRACED POINTER TO STRUCT
  306.                     magic      : INTEGER;
  307.                     version    : INTEGER;
  308.                     gadget     : I.Gadget;
  309.                     type       : SHORTINT;
  310.                     defaultTool: StringPtr;
  311.                     toolTypes  : e.APTR;
  312.                     currentX   : LONGINT;
  313.                     currentY   : LONGINT;
  314.                     drawerData : e.APTR;
  315.                     toolWindow : StringPtr;
  316.                     stackSize  : LONGINT;
  317.                   END;
  318.  
  319.   Args = STRUCT (dummy: d.ArgsStruct)
  320.            b     : LongPtr;
  321.            c     : StringPtr;
  322.            d     : StringPtr;
  323.            e     : StringPtr;
  324.            f     : StringPtr;
  325.            i     : StringPtr;
  326.            o     : StringPtr;
  327.            p     : LongPtr;
  328.            q     : StringPtr;
  329.            s     : LongPtr;
  330.            t     : LongPtr;
  331.            u     : StringPtr;
  332.            x     : LongPtr;
  333.            w     : StringPtr;
  334.            wl    : LongPtr;
  335.            wt    : LongPtr;
  336.            ww    : LongPtr;
  337.            wh    : LongPtr;
  338.            file  : StringPtr;
  339.          END;
  340.  
  341. (*------  Memory:  ------*)
  342.  
  343. CONST ChunkSize = 16384;          (* size of allocated chunks *)
  344.  
  345. TYPE
  346.   MemChunkPtr = UNTRACED POINTER TO MemChunk;  (* chunklist *)
  347.  
  348.   MemChunk = STRUCT
  349.                prev: MemChunkPtr;     (* link *)
  350.                data: ARRAY ChunkSize OF CHAR; (* ChunkSize Bytes of memory *)
  351.              END;
  352.  
  353.  
  354. (*------  Globals  ------*)
  355.  
  356. VAR
  357.   pub            : I.ScreenPtr;        (* default public screen             *)
  358.   Screen         : I.ScreenPtr;        (* MuchMore's Screen                 *)
  359.   Window         : I.WindowPtr;        (* MuchMore's Window                 *)
  360.   rp             : g.RastPortPtr;      (* Screen's RastPort                 *)
  361.   BM             : g.BitMapPtr;        (* Screen's BitMap                   *)
  362.   id             : LONGINT;            (* Display ID                        *)
  363.   catalog        : loc.CatalogPtr;     (* The Catalog                       *)
  364.   MyFile         : d.FileHandlePtr;    (* For loading Textfile              *)
  365.   MyAttr         : g.TextAttr;         (* The selected Font attributes      *)
  366.   MyFont         : g.TextFontPtr;      (* The selected Font                 *)
  367.   FontName       : String;             (* My Font Name or                   *)
  368.   FontSize       : INTEGER;            (* My Font Size                      *)
  369.   FirstLine      : TextLinePtr;        (* the topmost Line                  *)
  370.   TopLine        : TextLinePtr;        (* the topmost Line                  *)
  371.   BottomLine     : TextLinePtr;        (* Last Line displayed on Screen     *)
  372.   LoadLine       : TextLinePtr;        (* currently loaded Line             *)
  373.   LastLine       : TextLinePtr;        (* Last element of LineList          *)
  374.   writeText      : TextLine;           (* temp. Text Line                   *)
  375.   Name,OldName   : String;             (* Text's Name                       *)
  376.   option         : String;             (* CLI Option                        *)
  377.   pubscreenname  : String;
  378.   zoomBox        : ARRAY 4 OF INTEGER;
  379.   editcmd        : String;
  380.   Pens           : String;             (* Screen colors                     *)
  381.   Cols           : ARRAY 4 OF INTEGER; (* Color array for LoadRGB4          *)
  382.   busyPointer    : UNTRACED POINTER TO BusyPointer;
  383.   icon           : DiskObjectPtr;      (* info                              *)
  384.   nameptr        : StringPtr;          (* String Pointer                    *)
  385.   chptr          : CharPtr;            (* Char Pointer                      *)
  386.   PStr           : String;             (* The command for Dos.Execute       *)
  387.   Buffer         : UNTRACED POINTER TO ARRAY BufferSize OF CHAR; (* ReadBuf *)
  388.   RQPos          : LONGINT;            (* Position within ReadBuffer        *)
  389.   RQLen          : LONGINT;            (* Number of CHARs in Buffer         *)
  390.   AnzLines       : LONGINT;            (* Length of Text in Lines           *)
  391.   NumLines       : INTEGER;            (* Number of Lines on Screen         *)
  392.   fontWidth,fontHeight: INTEGER;       (* Font size                         *)
  393.   fontBaseLine   : INTEGER;            (* Font base line                    *)
  394.   spacing        : INTEGER;            (* Extra Line Spacing                *)
  395.   NumColumns     : INTEGER;            (* Number of Columns on Screen       *)
  396.   PageHeight     : INTEGER;            (* fontHeight*NumLines               *)
  397.   i,j            : INTEGER;            (* count                             *)
  398.   left,top       : INTEGER;            (* Dimensions of MMs window          *)
  399.   width,height   : INTEGER;
  400.   initialheight  : INTEGER;
  401.   depth          : INTEGER;            (* Number of planes                  *)
  402.   ci             : INTEGER;            (* Color index                       *)
  403.   scrollmode     : INTEGER;            (* The scrollmode                    *)
  404.   taskpri,oldpri : SHORTINT;           (* Muchmore's Task Priority          *)
  405.   MyLock,OldDir  : d.FileLockPtr;      (* To Examine and Load File          *)
  406.   oldcd          : d.FileLockPtr;      (* To save old CD                    *)
  407.   progdir        : d.FileLockPtr;      (* Lock on PROGDIR:                  *)
  408.   clock          : d.FileLockPtr;      (* Lock on C:                        *)
  409.   FileInfo       : d.FileInfoBlockPtr; (* to get File's length              *)
  410.   FileLength,TextLength : LONGINT;     (* Length of File and Displayed Text *)
  411.   ReadLength     : LONGINT;            (* Length of Text while reading      *)
  412.   ScreenPos      : INTEGER;            (* actual position within bitmap     *)
  413.   ShowTask       : e.TaskPtr;          (* the task that displays the text   *)
  414.   ShowStack      : e.APTR;             (* it's stack                        *)
  415.   ShowTaskRunning: BOOLEAN;            (* is Showtask activated?            *)
  416.   win            : BOOLEAN;            (* Is MM running in a window?        *)
  417.   interleaved    : BOOLEAN;            (* Use interleaved Screen?           *)
  418.   zoomed         : BOOLEAN;            (* Is MM iconified ?                 *)
  419.   stdin          : BOOLEAN;            (* Are we reading from STDIN ?       *)
  420.   SignalNewData  : BOOLEAN;            (* Signal when new data is loaded    *)
  421.   SignalAllRead  : BOOLEAN;            (* send signal at end of text        *)
  422.   Done           : BOOLEAN;            (* Quit                              *)
  423.   print          : BOOLEAN;            (* print text?                       *)
  424.   save           : BOOLEAN;            (* save block?                       *)
  425.   copy           : BOOLEAN;            (* copy block to clipboard?          *)
  426.   NewText        : BOOLEAN;            (* load new text                     *)
  427.   Info           : BOOLEAN;            (* is info currently displayed ?     *)
  428.   modeReq        : BOOLEAN;            (* Show Display Mode Requester?      *)
  429.   Scroll         : BOOLEAN;            (* scrolling or waiting?             *)
  430.   Fast           : BOOLEAN;            (* scroll quick?                     *)
  431.   Sync           : BOOLEAN;            (* scroll very quick?                *)
  432.   Decrunched     : BOOLEAN;            (* Is file decrunched?               *)
  433.   Scrollable     : BOOLEAN;            (* is screen able to scroll?         *)
  434.   refresh        : BOOLEAN;            (* Refresh Window?                   *)
  435.   oldstyle       : BOOLEAN;            (* Page Up/Down with soft scroll?    *)
  436.   lace           : BOOLEAN;            (* Is screen interlaced?             *)
  437.   cLocked        : BOOLEAN;            (* Is C: locked ?                    *)
  438.   NewDisp        : BOOLEAN;            (* need to rebuild Display ?         *)
  439.   fastquit       : BOOLEAN;
  440.   style          : SHORTSET;           (* Text style                        *)
  441.   mySig          : LONGSET;            (* My Signal Set                     *)
  442.   showSig        : LONGSET;            (* ShowTask's Signal Set             *)
  443.   Me             : d.ProcessPtr;       (* my main task                      *)
  444.   meInt          : LONGINT;            (* for making unique filename        *)
  445.   MyMsgPtr       : I.IntuiMessagePtr;  (* for receiving Messages            *)
  446.   in,out         : d.FileHandlePtr;    (* i/o for TYPE xxx TO PRT:          *)
  447.   mySigBit       : INTEGER;            (* My Signal Bit                     *)
  448.   showSigBit     : INTEGER;            (* ShowTask's Sig Bit                *)
  449.   frame          : INTEGER;            (* Frame Count                       *)
  450.   fg,bg          : INTEGER;            (* Text colors                       *)
  451.   oldfg,oldbg    : INTEGER;            (* Old Text colors                   *)
  452.   tabw           : INTEGER;            (* Tabulator width                   *)
  453.   rd             : d.RDArgsPtr;        (* For ReadArgs                      *)
  454.   args           : Args;               (* My CLI Args                       *)
  455.   ArgPtr         : StringPtr;          (* to get WBArg                      *)
  456.   wbm            : WBStartupPtr;       (* WBenchMessage                     *)
  457.   ri             : g.RasInfoPtr;       (* Screen's ViewPort's RasInfo       *)
  458.   dims           : g.DimensionInfo;    (* Dims for KS2.0                    *)
  459.   disp           : g.DisplayInfo;      (* DisplayInfo for KS2.0             *)
  460.   StrGadget      : I.Gadget;           (* Gadget for Find-Command           *)
  461.   StrInfo        : I.StringInfo;       (* its special info                  *)
  462.   asl            : e.LibraryPtr;       (* ASL-librarybase                   *)
  463.   diskFontBase   : e.LibraryPtr;       (* DiskFont-LibraryBase              *)
  464.   xpk            : e.LibraryPtr;       (* XpkMaster-Librarybase             *)
  465.   iconBase       : e.LibraryPtr;       (* Icon-Librarybase                  *)
  466.   Filename       : String;             (* The Filename (without path)       *)
  467.   Dirname        : String;             (* its path                          *)
  468.   Pattern        : ARRAY 80 OF CHAR;   (* The pattern for Filerequester     *)
  469.   TextMarkers    : ARRAY 10 OF TextLinePtr; (* Marked Positions in text     *)
  470.   FindLine       : TextLinePtr;        (* Last found line                   *)
  471.   KeyMap         : ARRAY 50H OF CHAR;  (* console's KeyMap                  *)
  472.   Password       : String;             (* Password for encrypted texts      *)
  473.   conreq         : e.IOStdReqPtr;      (* Console IO-Request                *)
  474.   console        : e.DevicePtr;        (* the console.device                *)
  475.   ievent         : ie.InputEventPtr;   (* InputEvent to convert keycodes    *)
  476.   WriteName      : String;             (* File to write Block               *)
  477.   savefrom,savesize: LONGINT;          (* How much to save?                 *)
  478.   iff            : ip.IFFHandlePtr;    (* IFF Handle for clipboard copy     *)
  479.   buffer         : UNTRACED POINTER TO CHAR; (* Save buffer                 *)
  480.   MemIndex       : INTEGER;            (* index in current Chunk            *)
  481.   CurChunk       : MemChunkPtr;        (* current chunk                     *)
  482.   c              : CHAR;               (* \ used by GetTextLine();          *)
  483.   le             : INTEGER;            (* / global for speed                *)
  484.  
  485.  
  486. (*-------------------------------------------------------------------------*)
  487.  
  488. PROCEDURE OpenDiskFont*{diskFontBase,-30}(VAR textAttr{8}: g.TextAttr): g.TextFontPtr;
  489.  
  490. PROCEDURE GetDiskObject {iconBase,- 78}(name{8}        : ARRAY OF CHAR): DiskObjectPtr;
  491. PROCEDURE FreeDiskObject{iconBase,- 90}(diskobj{8}     : DiskObjectPtr);
  492. PROCEDURE FindToolType  {iconBase,- 96}(toolTypes{8}   : e.APTR;
  493.                                         typeName{9}    : ARRAY OF CHAR): StringPtr;
  494. PROCEDURE MatchToolValue{iconBase,-102}(typeString{8}  : ARRAY OF CHAR;
  495.                                         val{9}         : ARRAY OF CHAR): BOOLEAN;
  496.  
  497. (*-------------------------------------------------------------------------*)
  498.  
  499. (* $Debug- *)
  500.  
  501. PROCEDURE StuffChar; (* $EntryExitCode- *)
  502. BEGIN
  503.   SYS.INLINE(016C0U, 04E75U)
  504. END StuffChar;
  505.  
  506.  
  507. (*-------------------------------------------------------------------------*)
  508.  
  509.  
  510. PROCEDURE LocStr (num: LONGINT): e.STRPTR;
  511. VAR default: e.STRPTR;
  512.  
  513. BEGIN
  514.   default := MSGS[num];
  515.   IF loc.base=NIL THEN RETURN default
  516.                   ELSE RETURN loc.GetCatalogStr(catalog,num,default^) END;
  517. END LocStr;
  518.  
  519.  
  520. (*-----------------------------  Requester:  ------------------------------*)
  521.  
  522.  
  523. PROCEDURE Request(Text: ARRAY OF CHAR); (* $CopyArrays- *)
  524. VAR es: I.EasyStruct;
  525.  
  526. BEGIN
  527.   IF ol.wbStarted THEN
  528.     es.structSize   := SIZE(I.EasyStruct);
  529.     es.flags        := LONGSET{};
  530.     es.title        := SYS.ADR(MuchText);
  531.     es.textFormat   := SYS.ADR(Text);
  532.     es.gadgetFormat := LocStr(MSGOK);
  533.     IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN END;
  534.   ELSE
  535.     SYS.SETREG(0,d.Write(d.Output(),Text,str.Length(Text)));
  536.     SYS.SETREG(0,d.Write(d.Output(),"\n",1));
  537.   END;
  538.   HALT(d.fail);
  539. END Request;
  540.  
  541.  
  542. PROCEDURE OutOfMemHandler;
  543. VAR es: I.EasyStruct;
  544.  
  545. BEGIN
  546.   es.structSize   := SIZE(I.EasyStruct);
  547.   es.flags        := LONGSET{};
  548.   es.title        := SYS.ADR(MuchText);
  549.   es.textFormat   := LocStr(MSGOOM);
  550.   es.gadgetFormat := LocStr(MSGRETRYABORT);
  551.   IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN
  552.     HALT(d.fail)
  553.   END;
  554. END OutOfMemHandler;
  555.  
  556.  
  557. (*-------------------------------------------------------------------------*)
  558.  
  559.  
  560. PROCEDURE AllocLine(sz: INTEGER): TextLinePtr;
  561.  
  562. VAR newchunk: MemChunkPtr;
  563.  
  564. BEGIN
  565.   INC(sz,SIZE(TextLine)-MaxLen); IF ODD(sz) THEN INC(sz) END;
  566.   IF MemIndex+sz<=ChunkSize THEN     (* does mem fit into current chunk ? *)
  567.     INC(MemIndex,sz);                (* increment index in current chunk  *)
  568.   ELSE
  569.     NEW(newchunk);                   (* allocate new chunk                *)
  570.     newchunk.prev := CurChunk;       (* link chunk into list              *)
  571.     CurChunk := newchunk;
  572.     MemIndex := sz;
  573.   END;
  574.   RETURN SYS.ADR(CurChunk.data[MemIndex-sz]);
  575. END AllocLine;
  576.  
  577.  
  578. PROCEDURE DisposeLines();
  579.  
  580. VAR chunk: MemChunkPtr;
  581.  
  582. BEGIN
  583.   WHILE CurChunk#NIL DO
  584.     chunk := CurChunk.prev;
  585.     DISPOSE(CurChunk);
  586.     CurChunk := chunk;
  587.   END;
  588.   MemIndex := ChunkSize;
  589. END DisposeLines;
  590.  
  591.  
  592. (*-------------------------------------------------------------------------*)
  593.  
  594.  
  595. PROCEDURE Busy;
  596. BEGIN
  597.   IF Window#NIL THEN
  598.     I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.rawKey,I.mouseButtons});
  599.     IF I.base.libNode.version >= 39 THEN
  600.       I.SetWindowPointer(Window,I.waBusyPointer,I.LTRUE,u.done);
  601.     ELSE
  602.       I.SetPointer(Window,busyPointer^,16,16,-6,0);
  603.     END;
  604.   END;
  605. END Busy;
  606.  
  607.  
  608. PROCEDURE UnBusy;
  609. BEGIN
  610.   IF Window#NIL THEN
  611.     IF I.base.libNode.version >= 39 THEN
  612.       I.SetWindowPointer(Window,u.done);
  613.     ELSE
  614.       I.ClearPointer(Window);
  615.     END;
  616.     I.OldModifyIDCMP(Window,MyIdcmp);
  617.   END;
  618. END UnBusy;
  619.  
  620.  
  621. (*------  Scroll:  ------*)
  622.  
  623. PROCEDURE MakeScroll(sync,fast,always: BOOLEAN);
  624. VAR m: INTEGER;
  625.  
  626. BEGIN
  627.   IF Scrollable THEN
  628.     m := 1;
  629.     IF ~always THEN
  630.       IF lace & ~fast THEN m := 2 END;
  631.       IF ~sync THEN INC(m,m*2) END;
  632.     END;
  633.     IF (m=1) OR (frame MOD m=0) THEN
  634.  
  635.       CASE scrollmode OF
  636.  
  637.       | 1: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  638.            g.WaitTOF;
  639.  
  640.       | 2: I.OldMakeScreen(Screen);
  641.            I.OldRethinkDisplay();
  642.  
  643.       (* 3: ScrollRaster *)
  644.  
  645.       | 4: g.WaitTOF;
  646.            g.ScrollVPort(SYS.ADR(Screen.viewPort));
  647.  
  648.       | 5: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  649.            g.WaitBOVP(SYS.ADR(Screen.viewPort));
  650.  
  651.       ELSE (* 0: *)
  652.            I.OldMakeScreen(Screen);
  653.            e.Forbid; g.MrgCop(I.ViewAddress()); e.Permit;
  654.            g.WaitTOF;
  655.  
  656.       END;
  657.     END;
  658.     (* $OvflChk- *)
  659.     INC(frame);
  660.     (* $OvflChk= *)
  661.   END;
  662. END MakeScroll;
  663.  
  664.  
  665. (*------  Clear Display:  ------*)
  666.  
  667. PROCEDURE ClearDisplay;
  668. BEGIN
  669.   IF win THEN
  670.     g.SetAPen(rp,0);
  671.     g.RectFill(rp,left,top,left+width-1,top+height-1);
  672.   ELSE
  673.     g.SetRast(rp,0);
  674.   END;
  675.   IF Scrollable THEN
  676.     ri.ryOffset := 0;
  677.     ScreenPos := 0;
  678.     MakeScroll(f,f,w);
  679.   END;
  680. END ClearDisplay;
  681.  
  682. (*-------------------------------------------------------------------------*)
  683.  
  684. (*------  Read one TextLine into a Variable:  ------*)
  685.  
  686.  
  687. PROCEDURE GetTextLine(): TextLinePtr;
  688. (* returns NIL at EOF *)
  689.  
  690. VAR
  691.   l        : TextLinePtr;
  692.   sz,wd,i,j: INTEGER;
  693.   txt      : ARRAY MaxLen+1 OF CHAR;
  694.   num      : ARRAY 10 OF INTEGER;
  695.   newcol   : BOOLEAN;
  696.   oldstyle : SHORTSET;
  697.  
  698.   PROCEDURE GetCh();
  699.   BEGIN
  700.     IF RQPos=RQLen THEN
  701.       RQLen := d.Read(MyFile,Buffer^,BufferSize);
  702.       IF RQLen<0 THEN Request(LocStr(MSGRWERR)^) END;
  703.       RQPos := 0;
  704.     END;
  705.     IF RQLen=0 THEN c := 0X ELSE
  706.       c := Buffer[RQPos]; IF c=0X THEN c:=1X END;
  707.       INC(RQPos); INC(le);
  708.     END;
  709.   END GetCh;
  710.  
  711. BEGIN
  712.   IF RQLen=0 THEN RETURN NIL END;
  713.   sz := 0; wd := 0; le := 0;
  714.   IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END; INC(sz)
  715.                      ELSE IF Bold IN style THEN txt[sz] := bold; INC(sz) END                      END;
  716.   IF   Ulin IN style     THEN txt[sz] := ulineon; INC(sz) END;
  717.   IF    Inv IN style     THEN txt[sz] := CHR(fg+4*bg+1); INC(sz)
  718.   ELSIF (fg#1) OR (bg#0) THEN txt[sz] := CHR(bg+4*fg+1); INC(sz) END;
  719.   LOOP
  720.     LOOP
  721.       GetCh;
  722.       IF SYS.VAL(CHAR,SYS.VAL(SHORTSET,c)*SHORTSET{0..6})#1BX THEN EXIT END;
  723.       i := -1;
  724.       REPEAT
  725.         GetCh;
  726.         IF (c>=30X) & (c<=39X) THEN
  727.           INC(i); num[i] := 0;
  728.           REPEAT
  729.             num[i] := 10*num[i]+ORD(c)-ORD(30X); GetCh;
  730.           UNTIL (c<30X) OR (c>39X);
  731.         END;
  732.         c := CAP(c);
  733.       UNTIL (c>=3FX(*"?"*)) & (c<=5AX) OR (c=0X) OR (i=9);
  734.       IF c=4DX THEN
  735.         newcol := f; oldstyle := style; j := 0;
  736.         IF i=-1 THEN i:=0; num[0] := 0 END;
  737.         WHILE (i>=j) & (sz<MaxLen-1) DO
  738.           CASE num[j] OF
  739.           0:  style := SHORTSET{}; fg := 1; bg := 0; newcol := w |
  740.           1:  INCL(style,Bold) |
  741.           2:  fg := 2; newcol := w |
  742.           3:  INCL(style,Italic) |
  743.           4:  INCL(style,Ulin) |
  744.           7:  INCL(style,Inv); newcol := w |
  745.           8:  oldfg:=fg; oldbg:=bg; fg:=0; bg:=0; newcol := w |
  746.  
  747.           22: EXCL(style,Bold); fg := 1; newcol := w |
  748.           23: EXCL(style,Italic) |
  749.           24: EXCL(style,Ulin) |
  750.           27: EXCL(style,Inv); newcol := w |
  751.           28: fg:=oldfg; bg:=oldbg; newcol := w |
  752.  
  753.           30..37: fg := (num[j]-30) MOD 4; newcol := w |
  754.           39:     fg := 1; newcol := w |
  755.  
  756.           40..47: bg := (num[j]-40) MOD 4; newcol := w |
  757.           49:     bg := 0; newcol := w |
  758.  
  759.           ELSE END;
  760.           INC(j);
  761.         END;
  762.         IF (oldstyle#style) & (sz<MaxLen) THEN
  763.           IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END;
  764.                              ELSE IF Bold IN style THEN txt[sz] := bold   ELSE txt[sz] := plain  END;
  765.           END;
  766.           INC(sz);
  767.           IF (Ulin IN style) THEN
  768.             IF ~((Ulin IN oldstyle)) & (sz<MaxLen) THEN
  769.               txt[sz] := ulineon;
  770.               INC(sz);
  771.             END;
  772.           ELSE
  773.             IF (Ulin IN oldstyle) & (sz<MaxLen) THEN
  774.               txt[sz] := ulineoff;
  775.               INC(sz);
  776.             END;
  777.           END;
  778.         END;
  779.         IF newcol & (sz<MaxLen) THEN
  780.           IF Inv IN style THEN txt[sz] := CHR(fg+4*bg+1)
  781.                           ELSE txt[sz] := CHR(bg+4*fg+1) END;
  782.           INC(sz);
  783.         END;
  784.       END;   (* IF c="m" THEN *)
  785.     END;   (* LOOP *)
  786.     CASE c OF
  787.       020X.. 7FX:   txt[sz] := c; INC(sz); INC(wd) |
  788.       0A1X..0FFX:   txt[sz] := c; INC(sz); INC(wd) |
  789.       8X: (* BS *)  IF wd>0 THEN DEC(sz); DEC(wd); END |
  790.       9X: (* TAB *) REPEAT
  791.                       txt[sz] := 20X; INC(sz); INC(wd)
  792.                     UNTIL (sz=MaxLen) OR (wd=NumColumns) OR (sz MOD tabw=0) |
  793.       0A0X:         txt[sz] := 20X; INC(sz); INC(wd) |
  794.       0AX,0X,0CX:   EXIT
  795.     ELSE
  796.     END;
  797.     IF (wd>=NumColumns) OR (sz>=MaxLen) THEN EXIT END;
  798.   END;
  799.   txt[sz] := 0X; INC(sz);
  800.   l := AllocLine(sz);
  801.   l.len := le; l.size:= sz;
  802.   WHILE sz>0 DO DEC(sz); l.text[sz] := txt[sz] END;
  803.   INC(ReadLength,le);
  804.   RETURN l;
  805. END GetTextLine;
  806.  
  807.  
  808. (*------  Write Line to Screen:  ------*)
  809.  
  810.  
  811. PROCEDURE Type(pos: INTEGER; line: TextLinePtr);
  812.  
  813. VAR
  814.   style: SHORTSET;
  815.   front,back: SHORTINT;
  816.   c: CHAR;
  817.   last,i,x,y: INTEGER;
  818.   strPtr: StringPtr;
  819.  
  820. BEGIN
  821.   g.SetDrMd(rp,g.jam2);
  822.   IF Scrollable THEN
  823.     g.SetAPen(rp,0);
  824.     y := pos * fontHeight;
  825.     IF ~refresh THEN g.RectFill(rp,0,y,width-1,y+fontHeight-spacing-1) END;
  826.   END;
  827.   i := 0; x := 0; style := SHORTSET{}; front := 1; back := 0;
  828.   LOOP
  829.     WHILE line.text[i] < " " DO
  830.       c := line.text[i];
  831.       IF c=0X THEN EXIT END;
  832.       CASE c OF
  833.       plain   : style := style - SHORTSET{g.bold,g.italic} |
  834.       italic  : EXCL(style,g.bold); INCL(style,g.italic)   |
  835.       bold    : INCL(style,g.bold); EXCL(style,g.italic)   |
  836.       boldit  : style := style + SHORTSET{g.bold,g.italic} |
  837.       ulineon : INCL(style,g.underlined) |
  838.       ulineoff: EXCL(style,g.underlined) |
  839.       1X..10X : DEC(c);
  840.                 front := SHORT(ORD(c)) DIV 4;
  841.                 back  := SHORT(ORD(c)) MOD 4 |
  842.       ELSE END;
  843.       INC(i);
  844.     END;
  845.     strPtr := SYS.ADR(line.text[i]); last := i;
  846.     REPEAT INC(i) UNTIL line.text[i]<" ";
  847.     SYS.SETREG(0,g.SetSoftStyle(rp,style,-SHORTSET{}));
  848.     g.SetAPen(rp,front);
  849.     g.SetBPen(rp,back);
  850.     g.Move(rp,left+fontWidth*x,top+fontHeight*pos+fontBaseLine);
  851.     g.Text(rp,strPtr^,i-last);
  852.     INC(x,i-last);
  853.   END;
  854. END Type;
  855.  
  856.  
  857. PROCEDURE CopyScrollLine(pos: INTEGER);
  858. (* Kopiert die an pos geschriebene Zeile auf den entsprechenden
  859.  * DoubleBuffer-Bereich
  860.  * ACHTUNG: Darf nur aufgerufen werden, wenn Scrollable TRUE ist!
  861.  *)
  862.  
  863. VAR
  864.   y,z: INTEGER;
  865.  
  866. BEGIN
  867.   y := pos*fontHeight;
  868.   z := PageHeight;
  869.   IF pos >= NumLines THEN z := -z END;
  870.   SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+z, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  871. END CopyScrollLine;
  872.  
  873.  
  874. (*------  Copy String to TextLine:  ------*)
  875.  
  876.  
  877. PROCEDURE CopyToWriteText(String: StringPtr);
  878. VAR i,j : INTEGER;
  879.  
  880. BEGIN
  881.   e.CopyMem(String^,writeText.text,MaxLen-1);
  882.   j := 0;
  883.   FOR i := 0 TO SHORT(str.Length(writeText.text))-1 DO
  884.     IF writeText.text[i] >= " " THEN INC(j) END;
  885.     IF j >= NumColumns THEN
  886.       writeText.text[i] := 0X;
  887.       RETURN
  888.     END;
  889.   END;
  890. END CopyToWriteText;
  891.  
  892.  
  893. (*------  Write String to Screen (at any position):  ------*)
  894.  
  895.  
  896. PROCEDURE TypeTo(VAR text: TextLine; pos: INTEGER);
  897.  
  898. BEGIN
  899.   IF pos < NumLines THEN
  900.     IF Scrollable THEN
  901.       INC(pos,ScreenPos);
  902.       Type(pos,SYS.ADR(text));
  903.       CopyScrollLine(pos);
  904.     ELSE
  905.       Type(pos,SYS.ADR(text));
  906.     END;
  907.   END;
  908. END TypeTo;
  909.  
  910.  
  911. (*------  Write String to Screen (at any position):  ------*)
  912.  
  913.  
  914. PROCEDURE WriteTo(String: StringPtr; pos: INTEGER);
  915.  
  916. BEGIN
  917.   CopyToWriteText(String);
  918.   TypeTo(writeText,pos);
  919. END WriteTo;
  920.  
  921.  
  922. (*------  Write Line at Bottom of Text:  ------*)
  923.  
  924.  
  925. PROCEDURE AddBottomLine(Line: TextLinePtr; Fast: BOOLEAN);
  926. VAR i,y: INTEGER;
  927.  
  928. BEGIN
  929.   IF ~Scrollable THEN
  930.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  931.     IF Fast THEN
  932.       g.ScrollRaster(rp,0,fontHeight,left,top,left+width-1,top+height-1);
  933.       IF Sync THEN g.WaitTOF END;
  934.     ELSE
  935.       i := fontHeight;
  936.       REPEAT
  937.         IF Window.height=initialheight THEN (* Prevent crash under v37 *)
  938.           g.ScrollRaster(rp,0,1,left,top,left+width-1,top+height-1);
  939.         END;
  940.         IF Sync THEN g.WaitTOF END;
  941.         DEC(i);
  942.       UNTIL i=0;
  943.     END;
  944.     Type(NumLines-1,Line);
  945.   ELSE
  946.     Type(ScreenPos+NumLines,Line);
  947.     y := ScreenPos*fontHeight;
  948.     IF Fast THEN
  949.       INC(ri.ryOffset,fontHeight);
  950.       MakeScroll(Sync,w,f);
  951.       SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  952.     ELSE
  953.       i := fontHeight;
  954.       REPEAT
  955.         INC(ri.ryOffset);
  956.         MakeScroll(Sync,f,f);
  957.         SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,1, 0C0X, SHORTSET{0..7}, NIL));
  958.         INC(y);
  959.         DEC(i);
  960.       UNTIL i=0;
  961.     END;
  962.     INC(ScreenPos);
  963.     IF ScreenPos=NumLines THEN
  964.       ScreenPos := 0;
  965.       ri.ryOffset := 0;
  966.     END;
  967.   END;
  968. END AddBottomLine;
  969.  
  970.  
  971. (*------  Check whether BottomLine.next is NIL or not:  ------*)
  972.  
  973.  
  974. PROCEDURE TryBottomnext(): BOOLEAN;
  975. (* returns TRUE if BottomLine.next#NIL END; *)
  976.  
  977. BEGIN
  978.   IF (BottomLine.next=NIL) & (MyFile#NIL) THEN
  979.     SignalNewData := w;
  980.     SYS.SETREG(0,e.Wait(mySig));
  981.     SignalNewData := f;
  982.   END;
  983.   RETURN BottomLine.next#NIL;
  984. END TryBottomnext;
  985.  
  986.  
  987. (*------  Scroll down one Line:  ------*)
  988.  
  989.  
  990. PROCEDURE ScrollDown(Fast: BOOLEAN);
  991.  
  992. BEGIN
  993.   IF TryBottomnext() THEN
  994.     BottomLine := BottomLine.next;
  995.     INC(AnzLines);
  996.     INC(TextLength,BottomLine.len);
  997.   ELSE RETURN END;
  998.   IF AnzLines >= NumLines THEN TopLine := TopLine.next END;
  999.   AddBottomLine(BottomLine,Fast);
  1000. END ScrollDown;
  1001.  
  1002.  
  1003. (*------  Scroll Up one Line:  ------*)
  1004.  
  1005.  
  1006. PROCEDURE ScrUp (Fast: BOOLEAN);
  1007. VAR
  1008.   i,y: INTEGER;
  1009.  
  1010. BEGIN
  1011.   IF ~Scrollable THEN
  1012.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  1013.     IF Fast THEN
  1014.       g.ScrollRaster(rp,0,-fontHeight,left,top,left+width-1,top+height-1);
  1015.       IF Sync THEN g.WaitTOF END;
  1016.     ELSE
  1017.       i := fontHeight;
  1018.       REPEAT
  1019.         IF Window.height=initialheight THEN
  1020.           g.ScrollRaster(rp,0,-1,left,top,left+width-1,top+height-1);
  1021.         END;
  1022.         IF Sync THEN g.WaitTOF END;
  1023.         DEC(i)
  1024.       UNTIL i=0;
  1025.     END;
  1026.     IF TopLine.prev#NIL THEN Type(0,TopLine.prev) ELSE Type(0,FirstLine) END;
  1027.   ELSE
  1028.     IF ScreenPos=0 THEN
  1029.       ri.ryOffset := NumLines*fontHeight;
  1030.       ScreenPos := NumLines;
  1031.     END;
  1032.     DEC(ScreenPos);
  1033.     IF TopLine.prev#NIL THEN Type(ScreenPos,TopLine.prev) ELSE Type(ScreenPos,FirstLine) END;
  1034.     y := ScreenPos*fontHeight;
  1035.     IF Fast THEN
  1036.       DEC(ri.ryOffset,fontHeight);
  1037.       MakeScroll(Sync,w,f);
  1038.       SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,fontHeight , 0C0X, SHORTSET{0..7}, NIL));
  1039.     ELSE
  1040.       INC(y,fontHeight);
  1041.       i := fontHeight;
  1042.       REPEAT
  1043.         DEC(ri.ryOffset);
  1044.         MakeScroll(Sync,f,f);
  1045.         DEC(y);
  1046.         SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,1, 0C0X, SHORTSET{0..7}, NIL));
  1047.         DEC(i);
  1048.       UNTIL i=0;
  1049.     END;
  1050.   END;
  1051. END ScrUp;
  1052.  
  1053.  
  1054. PROCEDURE ScrollUp(Fast: BOOLEAN);
  1055.  
  1056. BEGIN
  1057.   IF (TopLine.prev#NIL) & (TopLine.prev.prev#NIL) THEN
  1058.     TopLine := TopLine.prev;
  1059.     DEC(TextLength,BottomLine.len);
  1060.     DEC(AnzLines);
  1061.     BottomLine := BottomLine.prev;
  1062.     ScrUp(Fast);
  1063.   END;
  1064. END ScrollUp;
  1065.  
  1066.  
  1067. (*------  Undo last AddBottomLine:  ------*)
  1068.  
  1069.  
  1070. PROCEDURE DelLine(Fast: BOOLEAN);
  1071.  
  1072. BEGIN
  1073.   ScrUp(Fast);
  1074.   Info := f;
  1075. END DelLine;
  1076.  
  1077.  
  1078. (*------  Convert String to Integer:  ------*)
  1079.  
  1080. PROCEDURE StrToInt(str: StringPtr; base: INTEGER): LONGINT;
  1081.  
  1082. VAR
  1083.   i,j: INTEGER;
  1084.   num: LONGINT;
  1085.   ch : CHAR;
  1086.   neg: BOOLEAN;
  1087.  
  1088. BEGIN
  1089.   num := 0; i := 0; neg := f;
  1090.   IF  str^[0] = '-'                   THEN str:=SYS.ADR(str[1]); neg := w END;
  1091.   IF  str^[0] = '$'                   THEN str:=SYS.ADR(str[1]); base:=16 END;
  1092.   IF (str^[0]='0')&(CAP(str^[1])='X') THEN str:=SYS.ADR(str[2]); base:=16 END;
  1093.   LOOP
  1094.     IF i=LEN(str^) THEN EXIT END;
  1095.     ch := CAP(str^[i]);
  1096.     IF ch=0X THEN EXIT END;
  1097.     j := ORD(ch);
  1098.     CASE ch OF
  1099.       "0".."9": DEC(j,ORD('0'))   |
  1100.       "A".."F": DEC(j,ORD('A')-10);
  1101.                 IF base=10 THEN base:=16; i:=-1; j:=0; num:=0 END;
  1102.       ELSE EXIT
  1103.     END;
  1104.     num := num * base + j;
  1105.     INC(i);
  1106.   END;
  1107.   IF neg THEN num := -num END;
  1108.   RETURN num
  1109. END StrToInt;
  1110.  
  1111.  
  1112. (*-------------------------------------------------------------------------*)
  1113.  
  1114.  
  1115. PROCEDURE GetLength(t: TextLinePtr);
  1116.  
  1117. BEGIN
  1118.   TextLength := 0; AnzLines := 0;
  1119.   WHILE t#NIL DO INC(AnzLines); INC(TextLength,t.len); t := t.prev END;
  1120. END GetLength;
  1121.  
  1122.  
  1123. (*-------------------------------------------------------------------------*)
  1124.  
  1125.  
  1126. PROCEDURE NewDisplay;
  1127. (* Zeichnet ab BottomLine neu *)
  1128.  
  1129. VAR
  1130.   i: INTEGER;
  1131.   l: TextLinePtr;
  1132.  
  1133. BEGIN
  1134.   IF ~refresh THEN ClearDisplay END;
  1135.   l := BottomLine.prev;
  1136.   IF l#NIL THEN BottomLine := l END;
  1137.   l := BottomLine;
  1138.   i := NumLines-1;
  1139.   WHILE (i>0) & TryBottomnext() DO
  1140.     BottomLine := BottomLine.next;
  1141.     DEC(i);
  1142.   END;
  1143.   WHILE (i>0) & (l.prev#NIL) DO
  1144.     l := l.prev;
  1145.     DEC(i);
  1146.   END;
  1147.   TopLine := l.next;
  1148.   WHILE i<NumLines DO
  1149.     BottomLine := l;
  1150.     TypeTo(BottomLine^,i);
  1151.     INC(i);
  1152.     l := l.next;
  1153.   END;
  1154.   GetLength(BottomLine);
  1155.   Scroll := f;
  1156.   Info := f;
  1157. END NewDisplay;
  1158.  
  1159.  
  1160. (*-------------------------------------------------------------------------*)
  1161.  
  1162.  
  1163. PROCEDURE GetString(VAR str: ARRAY OF CHAR; int,newdisp: BOOLEAN);
  1164. VAR
  1165.   Win: I.WindowPtr;
  1166.   msg: I.IntuiMessagePtr;
  1167.   class: LONGSET;
  1168.   l,t,w,h: INTEGER;
  1169.   screen: I.ScreenPtr;
  1170.  
  1171. BEGIN
  1172.   MakeScroll(f,f,TRUE);
  1173.   Busy;
  1174.   screen := Screen;
  1175.   w := width DIV 4 * 3;
  1176.   l := (width-w) DIV 2;
  1177.   t := height DIV 2;
  1178.   IF Screen # NIL THEN
  1179.     IF Scrollable THEN INC(t,ri.ryOffset) END;
  1180.     h := Screen.font.ySize+4;
  1181.   ELSE
  1182.     screen := Window.wScreen;
  1183.     INC(l,Window.leftEdge);
  1184.     INC(t,Window.topEdge);
  1185.     h := screen.font.ySize+4;
  1186.   END;
  1187.   StrGadget.leftEdge   := 4;
  1188.   StrGadget.topEdge    := 2;
  1189.   StrGadget.width      := w-8;
  1190.   StrGadget.height     := h-4;
  1191.   StrGadget.activation := {I.stringCenter,I.relVerify};
  1192.   IF int THEN INCL(StrGadget.activation,I.longint) END;
  1193.   StrGadget.gadgetType := I.strGadget;
  1194.   StrGadget.specialInfo:= SYS.ADR(StrInfo);
  1195.   StrInfo.buffer       := SYS.ADR(str);
  1196.   StrInfo.maxChars     := SHORT(LEN(str))-1;
  1197.  
  1198.   IF Scrollable THEN Screen.height := Screen.height * 2 END;
  1199.  
  1200.   Win := I.OpenWindowTagsA(NIL,
  1201.                            I.waLeft,  l,
  1202.                            I.waTop,   t,
  1203.                            I.waWidth, w,
  1204.                            I.waHeight,h,
  1205.                            I.waIDCMP, LONGSET{I.gadgetUp,I.activeWindow,I.inactiveWindow},
  1206.                            I.waFlags, LONGSET{I.rmbTrap,I.activate,I.noCareRefresh},
  1207.                            I.waGadgets,SYS.ADR(StrGadget),
  1208.                            I.waCustomScreen,screen,
  1209.                            u.done);
  1210.  
  1211.   IF Scrollable THEN Screen.height := Screen.height DIV 2 END;
  1212.  
  1213.   IF Win # NIL THEN
  1214.     e.WaitPort(Win.userPort);
  1215.     SYS.SETREG(0,I.ActivateGadget(StrGadget,Win,NIL));
  1216.     LOOP
  1217.       e.WaitPort(Win.userPort);
  1218.       msg := e.GetMsg(Win.userPort);
  1219.       IF msg # NIL THEN
  1220.         class := msg.class;
  1221.         e.ReplyMsg(msg);
  1222.         IF (I.gadgetUp IN class) OR (I.inactiveWindow IN class) THEN
  1223.           EXIT
  1224.         END;
  1225.       END;
  1226.     END;
  1227.     I.CloseWindow(Win); Win := NIL;
  1228.   END;
  1229.   UnBusy;
  1230.   IF newdisp & ~win THEN
  1231.     refresh := TRUE; BottomLine := TopLine; NewDisplay; refresh := f;
  1232.   END;
  1233. END GetString;
  1234.  
  1235.  
  1236. (*-------------------------------------------------------------------------*)
  1237.  
  1238.  
  1239. PROCEDURE OpenDisplay;
  1240. BEGIN
  1241.  
  1242.   (*------  Open Screen:  ------*)
  1243.  
  1244.   IF ~win THEN
  1245.  
  1246.     LOOP
  1247.   
  1248.       IF id=g.invalidID THEN
  1249.         id := g.defaultMonitorID;
  1250.         pub := I.LockPubScreen(NIL);
  1251.         IF pub # NIL THEN
  1252.           id := g.GetVPModeID(SYS.ADR(pub.viewPort));
  1253.           I.UnlockPubScreen(NIL,pub);
  1254.         END;
  1255.       END;
  1256.   
  1257.       IF g.GetDisplayInfoData(NIL,dims,SIZE(dims),g.dtagDims,id) > 0 THEN
  1258.         width  := dims.txtOScan.maxX - dims.txtOScan.minX + 1;
  1259.         height := dims.txtOScan.maxY - dims.txtOScan.minY + 1;
  1260.   
  1261.         IF g.GetDisplayInfoData(NIL,disp,SIZE(disp),g.dtagDisp,id) > 0 THEN
  1262.           lace := g.isLace IN disp.propertyFlags;
  1263.           Scrollable := (g.isDraggable IN disp.propertyFlags) & (scrollmode # 3);
  1264.           IF Scrollable THEN INC(height,height) END;
  1265.   
  1266.           Screen := I.OpenScreenTagsA(NIL,
  1267.                                      I.saLeft,       0,
  1268.                                      I.saTop,        0,
  1269.                                      I.saWidth,      width,
  1270.                                      I.saHeight,     height,
  1271.                                      I.saDepth,      depth,
  1272.                                      I.saDisplayID,  id,
  1273.                                      I.saInterleaved,SYS.VAL(SHORTINT,interleaved),
  1274.                                      I.saOverscan,   I.oScanText,
  1275.                                      I.saPens,       SYS.ADR("\xFF\xFF"),
  1276.                                      I.saQuiet,      I.LTRUE,
  1277.                                      u.end);
  1278.         END;
  1279.       END;
  1280.   
  1281.       IF Screen # NIL THEN EXIT END;
  1282.   
  1283.       DEC(depth);
  1284.       IF depth=0 THEN Request(LocStr(MSGCOS)^) END;
  1285.     END;
  1286.   
  1287.     rp := SYS.ADR(Screen.rastPort);
  1288.     BM := rp.bitMap;
  1289.     ri := Screen.viewPort.rasInfo;
  1290.   
  1291.     IF ci>0 THEN g.LoadRGB4(SYS.ADR(Screen.viewPort),Cols,ci) END;
  1292.  
  1293.     left := 0;
  1294.     top  := 0;
  1295.     width  := Screen.width;
  1296.     height := Screen.height;
  1297.  
  1298.   END;
  1299.  
  1300. (*------  Open Window:  ------*)
  1301.  
  1302.   IF win THEN
  1303.  
  1304.     IF pubscreenname="" THEN pub := I.LockPubScreen(NIL);
  1305.                         ELSE pub := I.LockPubScreen(pubscreenname) END;
  1306.     IF pub # NIL THEN
  1307.  
  1308.       zoomBox[0] := left;
  1309.       zoomBox[1] := top;
  1310.       zoomBox[2] := 200;
  1311.       zoomBox[3] := pub.barHeight+1;
  1312.  
  1313.       Window := I.OpenWindowTagsA(NIL,
  1314.                                   I.waTitle,    SYS.ADR(MuchText),
  1315.                                   I.waLeft,     left,
  1316.                                   I.waTop,      top,
  1317.                                   I.waWidth,    width,
  1318.                                   I.waHeight,   height,
  1319.                                   I.waPubScreen,pub,
  1320.                                   I.waIDCMP,    MyIdcmp,
  1321.                                   I.waFlags,    LONGSET{I.windowDrag,I.windowClose,I.windowDepth,I.rmbTrap,I.activate,I.noCareRefresh},
  1322.                                   I.waZoom,     SYS.ADR(zoomBox),
  1323.                                   u.done);
  1324.       I.UnlockPubScreen(NIL,pub);
  1325.     END;
  1326.  
  1327.   ELSE
  1328.  
  1329.     Window := I.OpenWindowTagsA(NIL,
  1330.                                 I.waLeft,    0,
  1331.                                 I.waTop,     10,
  1332.                                 I.waWidth,   width,
  1333.                                 I.waHeight,  height-10,
  1334.                                 I.waCustomScreen,Screen,
  1335.                                 I.waIDCMP,   MyIdcmp,
  1336.                                 I.waFlags,   LONGSET{I.rmbTrap,I.activate,I.borderless,I.noCareRefresh,I.simpleRefresh,I.backDrop},
  1337.                                 u.done);
  1338.   END;
  1339.  
  1340.   IF Window=NIL THEN Request(LocStr(MSGCOW)^) END;
  1341.   initialheight := Window.height;
  1342.  
  1343.   IF win THEN
  1344.     rp := Window.rPort;
  1345.     left   := Window.borderLeft; top    := Window.borderTop;
  1346.     width  := Window.gzzWidth;   height := Window.gzzHeight;
  1347.     Scrollable := f;
  1348.     IF g.base.libNode.version >= 39 THEN g.SetMaxPen(rp,ASH(LONG(1),depth)-1)
  1349.                                     ELSE rp.mask := SHORTSET{0..depth-1}   END;
  1350.   END;
  1351.  
  1352. (*------  Open Font:  ------*)
  1353.  
  1354.   IF FontName[0] # 0X THEN
  1355.     MyAttr.name := SYS.ADR(FontName);
  1356.     MyAttr.ySize := FontSize;
  1357.     IF diskFontBase # NIL THEN MyFont := OpenDiskFont(MyAttr) END;
  1358.     IF (MyFont # NIL) & ~(g.proportional IN MyFont.flags) THEN g.SetFont(rp,MyFont) END;
  1359.   END;
  1360.  
  1361.   LOOP
  1362.     fontWidth  := rp.font.xSize;
  1363.     fontHeight := rp.font.ySize;
  1364.     IF (fontWidth<=50) & (fontHeight<=50) & (fontWidth>=4) & (fontHeight>=4) THEN EXIT END;
  1365.     MyAttr.name := SYS.ADR("topaz.font");
  1366.     MyAttr.ySize := 8;
  1367.     MyFont := g.OpenFont(MyAttr);
  1368.     IF MyFont=NIL THEN HALT(d.fail) END;
  1369.     g.SetFont(rp,MyFont);
  1370.   END;
  1371.   INC(fontHeight,spacing);               (* extra spacing *)
  1372.   fontBaseLine := rp.font.baseline;
  1373.  
  1374.   NumColumns := width DIV fontWidth;
  1375.   IF Scrollable THEN NumLines   := (height DIV 2) DIV fontHeight;
  1376.                 ELSE NumLines   := height DIV fontHeight; END;
  1377.   PageHeight := fontHeight*NumLines;
  1378.   height :=     PageHeight;
  1379.  
  1380.   ClearDisplay;
  1381.  
  1382.   IF Scrollable THEN
  1383.     Screen.height := height;
  1384.     I.OldMakeScreen(Screen);
  1385.     I.OldRethinkDisplay;
  1386.   ELSIF win THEN
  1387.     INC(top,(Window.gzzHeight-height) DIV 2);
  1388.   END;
  1389.  
  1390. END OpenDisplay;
  1391.  
  1392.  
  1393. (*-------------------------------------------------------------------------*)
  1394.  
  1395.  
  1396. PROCEDURE * ShowProc;
  1397.  
  1398. VAR
  1399.   l           : TextLinePtr;
  1400.   Down        : BOOLEAN;          (* Scroll-Direction                  *)
  1401.   Shift       : BOOLEAN;          (* Shifted Keystroke ?               *)
  1402.   Alt         : BOOLEAN;          (* Altered Keystroke ?               *)
  1403.   wasInfo     : BOOLEAN;          (* was Info line displayed ?         *)
  1404.   found       : BOOLEAN;          (* TRUE, if find was successful      *)
  1405.   chr         : CHAR;             (* converted keycode                 *)
  1406.   caseDelta   : SHORTINT;         (* Case sensitive Search?            *)
  1407.   flen        : INTEGER;          (* length of findstring              *)
  1408.   i,j         : INTEGER;          (* Count                             *)
  1409.   Class       : LONGSET;          (* contains Message.class            *)
  1410.   Code        : INTEGER;          (* contains Message.code             *)
  1411.   Qualifier   : SET;              (* contains Message.qualifier        *)
  1412.   Find,FindStr: ARRAY 80 OF CHAR; (* findstring / capital findstring   *)
  1413.   Goto        : ARRAY 10 OF CHAR; (* string containing goto line #     *)
  1414.   li          : LONGINT;          (* longint value of line to go to    *)
  1415.   HiText      : TextLine;         (* Highlited textline                *)
  1416.   OldHiText   : TextLinePtr;      (* original, un-hilited text         *)
  1417.   skipTab     : ARRAY 256 OF INTEGER;(* for Boyer-Moore Alg.           *)
  1418.  
  1419.  
  1420.   PROCEDURE WaitAllRead();
  1421.  
  1422.   BEGIN
  1423.     IF MyFile # NIL THEN
  1424.       Busy;
  1425.       SignalAllRead := w;
  1426.       SYS.SETREG(0,e.Wait(showSig));
  1427.       SignalAllRead := f;
  1428.       UnBusy;
  1429.     END;
  1430.   END WaitAllRead;
  1431.  
  1432.  
  1433.   PROCEDURE HiLite(at,len: INTEGER);
  1434.   (* Hilites len chars of BottomLine.text starting at position at *)
  1435.  
  1436.   VAR
  1437.     c: INTEGER;
  1438.     col: CHAR;
  1439.  
  1440.   BEGIN
  1441.     OldHiText := BottomLine; HiText := OldHiText^; BottomLine := SYS.ADR(HiText);
  1442.     IF at+len+2<MaxLen THEN
  1443.       c := 0; col := 5X;
  1444.       WHILE c<at DO
  1445.         IF HiText.text[c]<CHR(17) THEN col := HiText.text[c] END;
  1446.         INC(c);
  1447.       END;
  1448.       HiText.text[at] := CHR(17-ORD(col));
  1449.       c := at; INC(len,at);
  1450.       WHILE c<len DO
  1451.         HiText.text[c+1] := OldHiText.text[c];
  1452.         INC(c);
  1453.       END;
  1454.       HiText.text[c+1] := col;
  1455.       REPEAT
  1456.         HiText.text[c+2] := OldHiText.text[c];
  1457.         INC(c);
  1458.       UNTIL HiText.text[c-1]=0X;
  1459.     END;
  1460.     IF HiText.next#NIL THEN HiText.next.prev := SYS.ADR(HiText) END;
  1461.     IF HiText.prev#NIL THEN HiText.prev.next := SYS.ADR(HiText) END;
  1462.   END HiLite;
  1463.  
  1464.  
  1465.   PROCEDURE UnHiLite();
  1466.  
  1467.   BEGIN
  1468.     IF HiText.next#NIL THEN HiText.next.prev := OldHiText END;
  1469.     IF HiText.prev#NIL THEN HiText.prev.next := OldHiText END;
  1470.   END UnHiLite;
  1471.  
  1472.  
  1473.   PROCEDURE CalcSkipTab;  (* Make skip-table for Boyer-Moore Alg. *)
  1474.   VAR i,j: INTEGER;
  1475.  
  1476.   BEGIN
  1477.     FOR i := 0 TO 255 DO skipTab[i] := flen END;
  1478.     i := 0;
  1479.     FOR j := flen-1 TO 0 BY -1 DO
  1480.       IF skipTab[ORD(FindStr[j])] = flen THEN
  1481.         skipTab[ORD(FindStr[j])] := i;
  1482.       END;
  1483.       INC(i);
  1484.     END;
  1485.   END CalcSkipTab;
  1486.  
  1487.  
  1488.   PROCEDURE Search(): BOOLEAN;
  1489.   (* Searches string and hilites it if found. Result is TRUE if string found *)
  1490.  
  1491.   VAR ch: CHAR;
  1492.       i,j,t: INTEGER;
  1493.  
  1494.   BEGIN
  1495.     IF flen > BottomLine.size THEN RETURN f END;
  1496.     i := flen-1;
  1497.     FOR j := flen-1 TO 0 BY -1 DO
  1498.       LOOP
  1499.         ch := BottomLine.text[i];
  1500.         CASE ch OF "a".."z","à".."ö","ø".."þ": DEC(ch,caseDelta) ELSE END;
  1501.         IF ch = FindStr[j] THEN EXIT END;
  1502.         t := skipTab[ORD(ch)];
  1503.         IF flen-j > t THEN INC(i,flen-j) ELSE INC(i,t) END;
  1504.         IF i >= BottomLine.size THEN RETURN f END;
  1505.         j := flen-1;
  1506.       END;
  1507.       DEC(i);
  1508.     END;
  1509.     INC(i); IF i<0 THEN RETURN f END;
  1510.     SYS.SETREG(0,TryBottomnext());
  1511.     FindLine := BottomLine;
  1512.     HiLite(i,flen);
  1513.     found := w; RETURN w;
  1514.   END Search;
  1515.  
  1516.  
  1517.   PROCEDURE ShowInfo(Fast: BOOLEAN);
  1518.   VAR IStr : String;
  1519.       fmt  : StringPtr;
  1520.       i    : INTEGER;
  1521.       data : STRUCT name : e.STRPTR;
  1522.                     perc : LONGINT;
  1523.                     tlen : LONGINT;
  1524.                     flen : LONGINT;
  1525.                     lins : LONGINT;
  1526.              END;
  1527.   BEGIN
  1528.     data.name := SYS.ADR(OldName);
  1529.     data.tlen := TextLength;
  1530.     data.flen := FileLength;
  1531.     IF data.flen=0 THEN data.flen := ReadLength END;
  1532.     IF data.flen=0 THEN data.flen := 1 END;
  1533.     data.perc := TextLength * 100 DIV data.flen;
  1534.     data.lins := AnzLines-1;
  1535.     fmt := LocStr(MSGINFOFMT);
  1536.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(IStr));
  1537.     IStr[0] := 7X; IF depth<2 THEN IStr[0] := 2X END;
  1538.     i := SHORT(str.Length(IStr));
  1539.     REPEAT IStr[i] := 20X; INC(i) UNTIL (i>=LEN(IStr)-2) OR (i>=NumColumns+2);
  1540.     IStr[i] := 0X;
  1541.     CopyToWriteText(SYS.ADR(IStr));
  1542.     AddBottomLine(SYS.ADR(writeText),Fast);
  1543.     Info := w;
  1544.     Scroll := f;
  1545.   END ShowInfo;
  1546.  
  1547.  
  1548.   PROCEDURE Help; (* executed when HELP or H is pressed *)
  1549.  
  1550.   CONST
  1551.     num = 25;
  1552.  
  1553.   VAR
  1554.     i,j  : INTEGER;
  1555.     help : ARRAY num OF StringPtr;
  1556.     fmt  : StringPtr;
  1557.     data : StringPtr;
  1558.     h1   : String;
  1559.  
  1560.   BEGIN
  1561.     data := SYS.ADR(Version);
  1562.     fmt := LocStr(MSGH1);
  1563.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(h1));
  1564.     help[ 0] := SYS.ADR(h1);
  1565.     help[ 1] := SYS.ADR("");
  1566.     help[ 2] := LocStr(MSGH2);
  1567.     help[ 3] := LocStr(MSGH3);
  1568.     help[ 4] := LocStr(MSGH4);
  1569.     help[ 5] := LocStr(MSGH5);
  1570.     help[ 6] := LocStr(MSGH6);
  1571.     help[ 7] := LocStr(MSGH7);
  1572.     help[ 8] := LocStr(MSGH8);
  1573.     help[ 9] := LocStr(MSGH9);
  1574.     help[10] := LocStr(MSGH10);
  1575.     help[11] := LocStr(MSGH11);
  1576.     help[12] := LocStr(MSGH12);
  1577.     help[13] := LocStr(MSGH13);
  1578.     help[14] := LocStr(MSGH24);
  1579.     help[15] := LocStr(MSGH14);
  1580.     help[16] := LocStr(MSGH23);
  1581.     help[17] := LocStr(MSGH15);
  1582.     help[18] := LocStr(MSGH16);
  1583.     help[19] := LocStr(MSGH17);
  1584.     help[20] := LocStr(MSGH18);
  1585.     help[21] := SYS.ADR("");
  1586.     help[22] := LocStr(MSGH19);
  1587.     help[23] := LocStr(MSGH21);
  1588.     help[24] := LocStr(MSGH22);
  1589.     ClearDisplay();
  1590.     j := (NumLines - num) DIV 2; IF j<0 THEN j:=0 END;
  1591.     i := 0;
  1592.     WHILE (i<num) & (i+j<NumLines) DO
  1593.       WriteTo(help[i],j+i);
  1594.       INC(i);
  1595.     END;
  1596.     LOOP
  1597.       e.WaitPort(Window.userPort);
  1598.       MyMsgPtr := e.GetMsg(Window.userPort);
  1599.       IF (LONGSET{I.rawKey,I.mouseButtons}*MyMsgPtr.class#LONGSET{}) & (MyMsgPtr.code<128) THEN EXIT END;
  1600.       e.ReplyMsg(MyMsgPtr);
  1601.     END;
  1602.     e.ReplyMsg(MyMsgPtr);
  1603.     BottomLine := TopLine;
  1604.     NewDisplay
  1605.   END Help;
  1606.  
  1607.  
  1608.   PROCEDURE Bottom;  (* executed when END or B is pressed *)
  1609.  
  1610.   BEGIN
  1611.     WaitAllRead;
  1612.     BottomLine := LastLine;
  1613.     NewDisplay
  1614.   END Bottom;
  1615.  
  1616.  
  1617.   PROCEDURE Space(): BOOLEAN;  (* executed if space or LMB is pressed *)
  1618.   (* IF result=w THEN EXIT END *)
  1619.  
  1620.   BEGIN
  1621.     IF (MyFile=NIL) & (BottomLine.next=NIL) THEN        (* End of file? *)
  1622.       IF wasInfo THEN RETURN w END;
  1623.       ShowInfo(Shift);
  1624.     ELSE
  1625.       IF Down THEN
  1626.         Scroll := ~Scroll;
  1627.         IF ~Scroll THEN ShowInfo(Fast) END;
  1628.       ELSE
  1629.         Down := w;
  1630.         Scroll := w;
  1631.       END;
  1632.       Fast := Shift;
  1633.     END;
  1634.     RETURN f;
  1635.   END Space;
  1636.  
  1637.  
  1638.   PROCEDURE BackSpace;  (* executed if backspace or RMB is pressed *)
  1639.  
  1640.   BEGIN
  1641.     Fast := Shift;
  1642.     Scroll := Down OR ~Scroll;
  1643.     Down := f
  1644.   END BackSpace;
  1645.  
  1646.  
  1647. BEGIN
  1648.   (* $IF SmallData *)
  1649.   SYS.SETREG(13,e.AbsExecBase.thisTask.userData);
  1650.   (* $END *)
  1651.  
  1652.   (* $IFNOT ClearVars *)
  1653.   Find[0] := 0X; FindStr[0] := 0X; Goto[0] := 0X;
  1654.   (* $END *)
  1655.  
  1656.   Down := w;
  1657.  
  1658.   SYS.SETREG(0,e.AllocSignal(Window.userPort.sigBit));
  1659.   Window.userPort.sigTask := e.FindTask(NIL);
  1660.  
  1661.   showSigBit := e.AllocSignal(-1);
  1662.   showSig := LONGSET{showSigBit};
  1663.  
  1664.   e.Signal(Me,mySig);
  1665.   SYS.SETREG(0,e.Wait(showSig));
  1666.  
  1667.   LOOP
  1668.  
  1669.     IF NewDisp THEN NewDisp := f; NewDisplay END;
  1670.  
  1671. (*------  Type Text:  ------*)
  1672.  
  1673.     LOOP
  1674.       IF Scroll THEN
  1675.         IF Down THEN
  1676.           ScrollDown(Fast);
  1677.           Scroll := (MyFile#NIL) OR (BottomLine.next#NIL);
  1678.         ELSE
  1679.           ScrollUp(Fast);
  1680.           Scroll := (TopLine.prev#NIL) & (TopLine.prev.prev#NIL);
  1681.         END;
  1682.       ELSE
  1683.         MakeScroll(f,f,w);
  1684.         e.WaitPort(Window.userPort);
  1685.       END;
  1686.  
  1687.       MyMsgPtr := e.GetMsg(Window.userPort);
  1688.  
  1689.       IF MyMsgPtr # NIL THEN
  1690.         IF ~(I.inactiveWindow IN MyMsgPtr.class) THEN EXIT END;
  1691.         e.ReplyMsg(MyMsgPtr);
  1692.         I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.mouseButtons});
  1693.         e.WaitPort(Window.userPort);
  1694.         I.OldModifyIDCMP(Window,MyIdcmp);
  1695.       END;
  1696.  
  1697.     END;
  1698.  
  1699.     Code      := MyMsgPtr.code;
  1700.     Class     := MyMsgPtr.class;
  1701.     Qualifier := MyMsgPtr.qualifier;
  1702.  
  1703.     e.ReplyMsg(MyMsgPtr);
  1704.  
  1705.     Shift := {ie.lShift,ie.rShift,ie.capsLock} * Qualifier # {};
  1706.     Alt   := {ie.lAlt  ,ie.rAlt}               * Qualifier # {};
  1707.     Sync  := ~ (ie.control IN Qualifier);
  1708.  
  1709.     IF ~Sync THEN Shift := w END;
  1710.  
  1711.  
  1712.     IF ((I.rawKey       IN Class) & (Code<80H)) OR
  1713.        ((I.mouseButtons IN Class) & ({ie.leftButton,ie.rightButton}*Qualifier#{}))
  1714.     THEN
  1715.       wasInfo := f;
  1716.       IF Info THEN DelLine(Shift); wasInfo := w; END;
  1717.     END;
  1718.  
  1719.  
  1720.     IF I.mouseButtons IN Class THEN
  1721.  
  1722.       IF    (ie.leftButton IN Qualifier)   & Space()   THEN EXIT
  1723.       ELSIF ie.rightButton IN Qualifier THEN BackSpace END;
  1724.  
  1725.     ELSIF I.closeWindow IN Class THEN
  1726.       EXIT;
  1727.  
  1728.     ELSIF (I.newSize IN Class) THEN
  1729.       Scroll := f;
  1730.       zoomed := w;
  1731.       IF Window.height = initialheight THEN
  1732.         zoomed := f;
  1733.         BottomLine := TopLine;
  1734.         NewDisplay;
  1735.       END;
  1736.  
  1737.     ELSIF (I.rawKey IN Class) & (Code<80H) & ~zoomed THEN
  1738.  
  1739.       CASE Code OF
  1740.  
  1741.       | SPACE: IF Space() THEN EXIT END                     (* Space *)
  1742.  
  1743.       | BS:    BackSpace                                    (* BackSpace *)
  1744.  
  1745.       | DOWN,NK2,NK3:                                       (* Down *)
  1746.  
  1747.           IF (MyFile=NIL) & (BottomLine.next=NIL) THEN
  1748.             I.DisplayBeep(NIL)
  1749.           ELSE
  1750.             IF Shift & (Code # NK3) THEN
  1751.               Scroll := ~Down OR ~Scroll OR ~Fast;
  1752.               Fast := w; Down := w;
  1753.             ELSE
  1754.               IF Alt OR (Code=NK3) THEN
  1755.                 IF oldstyle THEN
  1756.                   i := NumLines-1;
  1757.                   REPEAT
  1758.                     ScrollDown(w);
  1759.                     DEC(i);
  1760.                   UNTIL i=0;
  1761.                 ELSE
  1762.                   IF BottomLine.next#NIL THEN BottomLine := BottomLine.next END;
  1763.                   NewDisplay;
  1764.                 END;
  1765.               ELSE
  1766.                 ScrollDown(w);
  1767.               END;
  1768.               Scroll := f;
  1769.             END;
  1770.           END;
  1771.  
  1772.       | UP,NK8,NK9:                                        (* Up *)
  1773.  
  1774.           IF (TopLine.prev=NIL) OR (TopLine.prev.prev=NIL) THEN
  1775.             I.DisplayBeep(NIL)
  1776.           ELSE
  1777.             IF Shift & (Code # NK9) THEN
  1778.               Scroll := Down OR ~Scroll OR ~Fast;
  1779.               Fast := w; Down := f;
  1780.             ELSE
  1781.               IF Alt OR (Code=NK9) THEN
  1782.                 i := NumLines-1;
  1783.                 IF oldstyle THEN
  1784.                   REPEAT
  1785.                     ScrollUp(w);
  1786.                     DEC(i);
  1787.                   UNTIL i=0;
  1788.                 ELSE
  1789.                   (*IF TopLine.prev#NIL THEN*)
  1790.                   BottomLine := TopLine;
  1791.                   WHILE (i>0) & (BottomLine.prev#NIL) DO
  1792.                     BottomLine := BottomLine.prev;
  1793.                     DEC(i);
  1794.                   END;
  1795.                   NewDisplay;
  1796.                   (*END;*)
  1797.                 END;
  1798.               ELSE
  1799.                 ScrollUp(w);
  1800.               END;
  1801.               Scroll := f;
  1802.             END;
  1803.           END;
  1804.  
  1805.       | CR,ENTER: ScrollDown(f); Scroll := f;              (* CR *)
  1806.  
  1807.       | NK7: BottomLine := FirstLine; NewDisplay           (* Home *)
  1808.  
  1809.       | NK1: Bottom                                        (* End *)
  1810.  
  1811.       | F1..F10:                                           (* F1..F10 *)
  1812.  
  1813.           i := Code-F1;
  1814.           IF ~ Shift & (TextMarkers[i]#NIL) THEN
  1815.             BottomLine := TextMarkers[i];
  1816.             NewDisplay;
  1817.           ELSE
  1818.             TextMarkers[i] := TopLine;
  1819.           END
  1820.  
  1821.       | NK0:  IF ~wasInfo THEN ShowInfo(Shift) END;        (* NK 0 *)
  1822.  
  1823.       | HELP: Help                                         (* Help *)
  1824.  
  1825.       | ESC:  EXIT                                         (* Quit *)
  1826.  
  1827.       | NK5:  IF wasInfo OR fastquit THEN EXIT ELSE ShowInfo(Shift)END; (* safe Quit *)
  1828.  
  1829.       ELSE
  1830.  
  1831.         IF Code<40H THEN         (* examine vanilla keycode: *)
  1832.  
  1833.           chr := KeyMap[Code];
  1834.  
  1835.           CASE chr OF
  1836.  
  1837.           | "t": BottomLine := FirstLine; NewDisplay       (* Home *)
  1838.  
  1839.           | "b": Bottom;                                   (* End *)
  1840.  
  1841.           | "f","n","p":                                   (* Find, Next, Previous *)
  1842.  
  1843.             IF chr="f" THEN
  1844.               caseDelta := 32; IF Shift THEN caseDelta := 0 END;
  1845.               GetString(Find,f,w);
  1846.               FindLine := NIL; flen := 0;
  1847.               LOOP
  1848.                 FindStr[flen] := Find[flen];
  1849.                 CASE FindStr[flen] OF
  1850.                   "a".."z","à".."ö","ø".."þ": DEC(FindStr[flen],caseDelta) |
  1851.                   0X: EXIT;
  1852.                 ELSE
  1853.                 END;
  1854.                 INC(flen);
  1855.               END;
  1856.               CalcSkipTab;
  1857.             END;
  1858.             found := f;
  1859.             IF FindStr[0]#0X THEN
  1860.               Busy;
  1861.               i := NumLines;
  1862.               IF FindLine # NIL THEN FindLine := FindLine.next END;
  1863.               WHILE (i>0) & (BottomLine#NIL) & (BottomLine#FindLine) DO
  1864.                 BottomLine := BottomLine.prev; DEC(i);
  1865.               END;
  1866.               IF (BottomLine # FindLine) OR (BottomLine=NIL) THEN
  1867.                 BottomLine := TopLine
  1868.               END;
  1869.               IF chr # "p" THEN                          (* next *)
  1870.                 WHILE (BottomLine # NIL) & ~ Search() DO
  1871.                   SYS.SETREG(0,TryBottomnext());
  1872.                   BottomLine := BottomLine.next;
  1873.                 END;
  1874.               ELSE                                       (* previous *)
  1875.                 IF BottomLine.prev#NIL THEN BottomLine:=BottomLine.prev END;
  1876.                 REPEAT
  1877.                   BottomLine := BottomLine.prev
  1878.                 UNTIL (BottomLine=NIL) OR Search();
  1879.               END;
  1880.               IF BottomLine#NIL THEN
  1881.                 li := NumLines DIV 2;
  1882.                 WHILE (li>0) & (BottomLine.prev#NIL) DO BottomLine := BottomLine.prev; DEC(li) END;
  1883.               END;
  1884.               UnBusy;
  1885.             END;
  1886.  
  1887.             IF ~ found THEN
  1888.               I.DisplayBeep(NIL);
  1889.               BottomLine := TopLine;
  1890.             END;
  1891.             NewDisplay;
  1892.             IF found THEN UnHiLite END;
  1893.  
  1894.           | "w","c":                                       (* write block *)
  1895.             IF (TextMarkers[0]#NIL) & (TextMarkers[1]#NIL) & ~print & ~save THEN
  1896.               savefrom := 0; savesize := 0;
  1897.               l := TextMarkers[0].prev; WHILE l.prev#NIL DO l := l.prev; INC(savefrom,l.len) END;
  1898.               l := TextMarkers[1].prev; WHILE l#NIL DO INC(savesize,l.len); l := l.prev END;
  1899.               l := TextMarkers[1]; i := NumLines; WHILE (i>1) & (l#NIL) DO DEC(i); INC(savesize,LONG(l.len)); l := l.next END;
  1900.               DEC(savesize,savefrom);
  1901.               IF savesize>0 THEN
  1902.                 IF chr="c" THEN copy := w ELSE
  1903.                   GetString(WriteName,f,w);
  1904.                   copy := f;
  1905.                 END;
  1906.                 WaitAllRead; save := w; e.Signal(Me,mySig);
  1907.               END
  1908.             END
  1909.  
  1910.           | "o","e":                                       (* Print, Edit *)
  1911.  
  1912.             IF Shift & Alt & ~print & ~save THEN
  1913.               nameptr := SYS.ADR(Name);
  1914.               IF chr="o" THEN
  1915.                 e.OldRawDoFmt('Type "%s" to PRT:',SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1916.               ELSE
  1917.                 e.OldRawDoFmt(editcmd,SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1918.               END;
  1919.               WaitAllRead; print := w; e.Signal(Me,mySig);
  1920.             END
  1921.  
  1922.           | "l":                                           (* Load Text *)
  1923.  
  1924.             ClearDisplay;
  1925.             NewText := w; e.Signal(Me,mySig);
  1926.             REPEAT UNTIL (showSigBit IN e.Wait(showSig)) & ~ NewText |
  1927.  
  1928.           | "g":                                           (* goto *)
  1929.  
  1930.             GetString(Goto,w,w);
  1931.             li := SHORT(StrInfo.longInt);
  1932.             Busy;
  1933.             BottomLine := FirstLine;
  1934.             WHILE (li >= 0) & TryBottomnext() DO
  1935.               BottomLine := BottomLine.next;
  1936.               DEC(li)
  1937.             END;
  1938.             UnBusy;
  1939.             NewDisplay
  1940.  
  1941.           | "h":     Help                                  (* Help *)
  1942.  
  1943.           | "q","x": IF wasInfo OR fastquit THEN EXIT ELSE ShowInfo(Shift) END; (* safe Quit *)
  1944.  
  1945.           ELSE END;
  1946.  
  1947.         END;   (* IF Code<40H THEN *)
  1948.  
  1949.       END;   (* CASE Code OF *)
  1950.  
  1951.     END;   (* IF I.rawKey IN Class THEN *)
  1952.  
  1953.   END;   (* LOOP *)
  1954.  
  1955.   Done := w;
  1956.   e.Signal(Me,mySig);
  1957.   LOOP SYS.SETREG(0,e.Wait(LONGSET{})) END;
  1958.  
  1959. END ShowProc;
  1960.  
  1961. (* $Debug= *)
  1962.  
  1963.  
  1964. (*--------------------------  File Requester:  ----------------------------*)
  1965.  
  1966.  
  1967. PROCEDURE FileReq(VAR Name: String);
  1968.  
  1969. CONST
  1970.   aslTag     = u.user + 80000H;
  1971.   taghail   = aslTag + 1;
  1972.   window    = aslTag + 2;
  1973.   leftEdge  = aslTag + 3;
  1974.   topEdge   = aslTag + 4;
  1975.   width     = aslTag + 5;
  1976.   height    = aslTag + 6;
  1977.   hookFunc  = aslTag + 7;
  1978.   file      = aslTag + 8;
  1979.   dir       = aslTag + 9;
  1980.   pattern   = aslTag + 10;
  1981.   funcFlags = aslTag + 20;
  1982.   screen    = aslTag + 40;
  1983.   sleepWindow=aslTag + 43;
  1984.  
  1985.   fiDir     = u.user + 50;
  1986.   patGad    = 0;
  1987.  
  1988. TYPE
  1989.   FileRequesterPtr = UNTRACED POINTER TO FileRequester;
  1990.  
  1991.   FileRequester = STRUCT
  1992.                     hail      : StringPtr;
  1993.                     ddef      : StringPtr;
  1994.                     ddir      : StringPtr;
  1995.                     wind      : I.WindowPtr;
  1996.                     funcFlags : SHORTSET;
  1997.                     flags2    : SHORTSET;
  1998.                     function  : PROCEDURE;
  1999.                     reserved2 : LONGINT;
  2000.                   END;
  2001. VAR
  2002.   fr: FileRequesterPtr;
  2003.   pub,scr: I.ScreenPtr;
  2004.   i,j: INTEGER;
  2005.   res: BOOLEAN;
  2006.   screenTag: LONGINT;
  2007.  
  2008.   PROCEDURE AllocAslRequest  {asl,-48} (type{0}: LONGINT; tag{8}..: e.APTR): FileRequesterPtr;
  2009.   PROCEDURE FreeAslRequest   {asl,-54} (fr{8}: FileRequesterPtr);
  2010.   PROCEDURE RequestFile      {asl,-42} (fr{8}: FileRequesterPtr): e.APTR;
  2011.  
  2012. BEGIN
  2013.   j := SHORT(str.Length(Name));
  2014.   WHILE (j>0) & (Name[j]#":") & (Name[j]#"/") DO DEC(j) END;
  2015.   IF j=0 THEN j := -1 END;
  2016.   i := 0;
  2017.   WHILE i<=j DO Dirname[i] := Name[i]; INC(i) END; Dirname[i] := 0X;
  2018.   j := 0;
  2019.   REPEAT Filename[j] := Name[i]; INC(j); INC(i) UNTIL Name[i-1]=0X;
  2020.  
  2021.   IF asl=NIL THEN
  2022.     asl := e.OpenLibrary("asl.library",36);
  2023.     IF asl=NIL THEN
  2024.       Request("Can't open asl.library")
  2025.     END;
  2026.   END;
  2027.  
  2028.   IF (Window # NIL) & (asl.version >= 38) THEN
  2029.     screenTag := screen;
  2030.     scr := Window.wScreen;
  2031.   ELSE
  2032.     screenTag := u.ignore;
  2033.     scr := NIL;
  2034.     pub := I.LockPubScreen(NIL);
  2035.     IF pub # NIL THEN
  2036.       I.ScreenToFront(pub);
  2037.       I.UnlockPubScreen(NIL,pub);
  2038.     END;
  2039.   END;
  2040.  
  2041.   fr := AllocAslRequest(0,  screenTag,scr,
  2042.                             taghail, SYS.ADR(MuchText),
  2043.                             file,    SYS.ADR(Filename),
  2044.                             dir,     SYS.ADR(Dirname),
  2045.                             pattern, SYS.ADR(Pattern),
  2046.                             funcFlags,ASH(1,patGad),
  2047.                             u.done);
  2048.   IF fr=NIL THEN Request(LocStr(MSGOOM)^) END;
  2049.  
  2050.   res := RequestFile(fr) # NIL;
  2051.  
  2052.   IF res THEN
  2053.     Filename := fr.ddef^;
  2054.     Dirname  := fr.ddir^;
  2055.   END;
  2056.   FreeAslRequest(fr);
  2057.   IF ~res THEN HALT(d.ok) END;
  2058.  
  2059.   Name := Dirname;
  2060.   i := SHORT(str.Length(Name));
  2061.   IF (i>0) THEN
  2062.     CASE Name[i-1] OF "/",":": ELSE
  2063.       Name[i] := "/"; INC(i);
  2064.     END;
  2065.   END;
  2066.   j := 0;
  2067.   LOOP
  2068.     Name[i] := Filename[j];
  2069.     IF (Name[i]=0X) OR (i=255) THEN EXIT END;
  2070.     INC(i);
  2071.     INC(j);
  2072.   END;
  2073.   Name[i] := 0X;
  2074.   IF Window # NIL THEN
  2075.     I.ScreenToFront(Window.wScreen);
  2076.     I.ActivateWindow(Window);
  2077.   END;
  2078. END FileReq;
  2079.  
  2080.  
  2081. (*--------------------------  Decrunch:  ----------------------------*)
  2082.  
  2083.  
  2084. PROCEDURE DirExists(name: ARRAY OF CHAR): BOOLEAN; (* $CopyArrays- *)
  2085. VAR lock: d.FileLockPtr;
  2086.     result: BOOLEAN;
  2087.     oldwp: e.APTR;
  2088. BEGIN
  2089.   result := f;
  2090.   oldwp := Me.windowPtr;
  2091.   Me.windowPtr := -1;
  2092.   lock := d.Lock(name,d.sharedLock);
  2093.   IF lock # NIL THEN
  2094.     result := w;
  2095.     d.UnLock(lock)
  2096.   END;
  2097.   Me.windowPtr := oldwp;
  2098.   RETURN result
  2099. END DirExists;
  2100.  
  2101.  
  2102. PROCEDURE Decrunch;
  2103.  
  2104. CONST
  2105.   tagBase    = u.user + ORD("X")*256 + ORD("P");
  2106.   inName     = tagBase+01H;
  2107.   inFH       = tagBase+02H;
  2108.   outName    = tagBase+10H;
  2109.   password   = tagBase+24H;
  2110.   getError   = tagBase+25H;
  2111.   shortError = tagBase+31H;
  2112.   typePacked = 1;
  2113.   flagsPassword = 0;
  2114.  
  2115. TYPE
  2116.   XpkFib = STRUCT
  2117.     type       : LONGINT;    (* Unpacked, packed, archive? *)
  2118.     uLen       : LONGINT;
  2119.     cLen       : LONGINT;
  2120.     nLen       : LONGINT;
  2121.     uCur       : LONGINT;
  2122.     cCur       : LONGINT;
  2123.     id         : LONGINT;
  2124.     packer     : ARRAY 6 OF CHAR;
  2125.     subVersion : INTEGER;
  2126.     masVersion : INTEGER;
  2127.     flags      : LONGSET;
  2128.     head       : ARRAY 16 OF CHAR;
  2129.     ratio      : LONGINT;
  2130.     reserved   : ARRAY 8 OF LONGINT;
  2131.   END;
  2132.  
  2133. VAR
  2134.   file: d.FileHandlePtr;
  2135.   err: LONGINT;
  2136.   xpkFib: XpkFib;
  2137.   errBuf: ARRAY 81 OF CHAR;
  2138.  
  2139.   PROCEDURE ExamineTags {xpk,-36}(VAR fib{8}  : XpkFib;
  2140.                                   tag1{9}..   : e.APTR): LONGINT;
  2141.   PROCEDURE UnpackTags  {xpk,-48}(tag1{8}..   : e.APTR): LONGINT;
  2142.  
  2143. BEGIN
  2144.   Decrunched := f;
  2145.   OldName := Name;
  2146.   IF stdin THEN RETURN END;
  2147.  
  2148.   IF DirExists("T:") THEN Name := "T:" ELSE Name := "RAM:" END;
  2149.  
  2150.   e.OldRawDoFmt("Decrunched.%lx",SYS.ADR(meInt),StuffChar,SYS.ADR(Name[str.Length(Name)]));
  2151.  
  2152.   IF xpk=NIL THEN
  2153.     xpk := e.OpenLibrary("xpkmaster.library",1);
  2154.   END;
  2155.   IF xpk#NIL THEN
  2156.     err := ExamineTags(xpkFib,inFH,SYS.VAL(LONGINT,MyFile),u.done);
  2157.     IF (err#0) & (err#-20) THEN
  2158.       Request(LocStr(MSGOOM)^)
  2159.     END;
  2160.     IF (err=-20) OR (xpkFib.type#typePacked) THEN
  2161.       Name := OldName;
  2162.       RETURN
  2163.     END;
  2164.     IF flagsPassword IN xpkFib.flags THEN GetString(Password,f,f) END;
  2165.     Busy;
  2166.     err := UnpackTags(inFH,       SYS.VAL(LONGINT,MyFile),
  2167.                       outName,    SYS.ADR(Name),
  2168.                       password,   SYS.ADR(Password),
  2169.                       getError,   SYS.ADR(errBuf),
  2170.                       shortError, e.true,
  2171.                       u.done);
  2172.     UnBusy;
  2173.     IF err#0 THEN Request(errBuf) END;
  2174.     file := d.Open(Name,d.oldFile);
  2175.     IF file#NIL THEN
  2176.       Decrunched := w;
  2177.       d.OldClose(MyFile);
  2178.       MyFile := file;
  2179.       RETURN
  2180.     ELSE
  2181.       Request(LocStr(MSGCOF)^);
  2182.     END;
  2183.   END;
  2184.   Name := OldName;
  2185. END Decrunch;
  2186.  
  2187.  
  2188. (*-----------------  Screen Mode Requester:  ------------------------*)
  2189.  
  2190.  
  2191. PROCEDURE GetNode (VAR list: e.List; index: LONGINT): e.NodePtr;
  2192.   VAR n: e.NodePtr;
  2193. BEGIN
  2194.   n := list.head;
  2195.   WHILE index > 0 DO
  2196.     IF n.succ=NIL THEN RETURN NIL END;
  2197.     n := n.succ;
  2198.     DEC(index);
  2199.   END;
  2200.   RETURN n;
  2201. END GetNode;
  2202.  
  2203.  
  2204. PROCEDURE ScreenModeReq (VAR displayID : LONGINT): INTEGER;
  2205. CONST
  2206.   gadLISTVIEW    = 1;
  2207.   gadBUTTONSave  = 2;
  2208.   gadBUTTONUse   = 3;
  2209.   gadBUTTONCancel= 4;
  2210.  
  2211.   Topaz80 = g.TextAttr(SYS.ADR("topaz.font"), 8, SHORTSET{}, SHORTSET{});
  2212.  
  2213. TYPE
  2214.   MyNodePtr = UNTRACED POINTER TO MyNode;
  2215.   MyNode = STRUCT (node: e.Node)
  2216.              displayID: LONGINT;
  2217.            END;
  2218.  
  2219. VAR
  2220.   ng            : gt.NewGadget;
  2221.   gad,glist     : I.GadgetPtr;
  2222.   Win           : I.WindowPtr;
  2223.   pub           : I.ScreenPtr;
  2224.   font          : g.TextAttrPtr;
  2225.   width,height  : INTEGER;
  2226.   txW,txH       : INTEGER;
  2227.   result,index  : INTEGER;
  2228.   firstindex    : INTEGER;
  2229.   topborder     : INTEGER;
  2230.   x1,x2,min     : INTEGER;
  2231.   terminated    : BOOLEAN;
  2232.   lvlist        : e.List;
  2233.   lvSelectedTag : LONGINT;
  2234.   vi            : e.APTR;
  2235.   imsg          : I.IntuiMessagePtr;
  2236.   node          : MyNodePtr;
  2237.   dispID        : LONGINT;
  2238.   displayInfo   : g.DisplayInfo;
  2239.   nameInfo      : g.NameInfo;
  2240.  
  2241.  
  2242.   PROCEDURE StrLen (str: e.STRPTR; min: INTEGER): INTEGER;
  2243.   VAR it: I.IntuiText;
  2244.       len: INTEGER;
  2245.   BEGIN
  2246.     (* $IFNOT ClearVars *)
  2247.     len := 0;
  2248.     it.leftEdge := 0; it.topEdge  := 0; it.frontPen := 0; it.backPen  := 0;
  2249.     it.drawMode := SHORTSET{}; it.nextText := NIL;
  2250.     (* $END *)
  2251.     IF str#NIL THEN
  2252.       it.iTextFont := font; it.iText := str;
  2253.       len := I.IntuiTextLength(it);
  2254.     END;
  2255.     IF len > min THEN RETURN len ELSE RETURN min END;
  2256.   END StrLen;
  2257.  
  2258. BEGIN
  2259.   (* $IFNOT ClearVars *)
  2260.   Win := NIL; vi := NIL; glist := NIL; pub := NIL; result := 0;
  2261.   (* $END *)
  2262.  
  2263.   LOOP
  2264.     pub := I.LockPubScreen(NIL);         IF pub=NIL THEN EXIT END;
  2265.     vi  := gt.GetVisualInfo(pub,u.done); IF vi =NIL THEN EXIT END;
  2266.     topborder := pub.wBorTop + pub.font.ySize + 1;
  2267.  
  2268.     font := pub.font;
  2269.     txW := pub.rastPort.txWidth; txH := pub.rastPort.txHeight;
  2270.     width := txW * 36 + 16; height := txH * 8 + 32;
  2271.     IF ((width+pub.wBorLeft+pub.wBorRight) > pub.width) OR ((height+topborder+pub.wBorBottom) > pub.height) THEN
  2272.       font := SYS.ADR(Topaz80);
  2273.       txW := 8; txH := 8;
  2274.       width := 8 * 36 + 16; height := 8 * 8 + 32;
  2275.     END;
  2276.     min := txW * 6;
  2277.  
  2278.     gad := gt.CreateContext(glist);
  2279.  
  2280.     ng.textAttr := font;
  2281.     ng.visualInfo := vi;
  2282.     ng.userData := NIL;
  2283.  
  2284.     ng.leftEdge := 16;
  2285.     ng.height := txH+4;
  2286.     ng.topEdge := topborder+height-ng.height-5;
  2287.     ng.gadgetText := LocStr(MSGSAVE);
  2288.     ng.width := StrLen(ng.gadgetText,min)+8;
  2289.     ng.gadgetID := gadBUTTONSave;
  2290.     ng.flags := LONGSET{};
  2291.     x1 := ng.leftEdge+ng.width;
  2292.  
  2293.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2294.  
  2295.     ng.gadgetText := LocStr(MSGCANCEL);
  2296.     ng.width := StrLen(ng.gadgetText,min)+8;
  2297.     ng.leftEdge := width-ng.width-8;
  2298.     ng.gadgetID := gadBUTTONCancel;
  2299.     x2 := ng.leftEdge;
  2300.  
  2301.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2302.  
  2303.     ng.gadgetText := LocStr(MSGUSE);
  2304.     ng.width := StrLen(ng.gadgetText,min)+8;
  2305.     ng.leftEdge := (x1+x2-ng.width) DIV 2;
  2306.     ng.gadgetID := gadBUTTONUse;
  2307.  
  2308.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2309.  
  2310.     lvlist.head := SYS.ADR(lvlist.tail);
  2311.     lvlist.tail := NIL;
  2312.     lvlist.tailPred := SYS.ADR(lvlist.head);
  2313.  
  2314.     index := 0;
  2315.     firstindex := -1;
  2316.     dispID := g.NextDisplayInfo(g.invalidID);
  2317.  
  2318.     WHILE dispID # g.invalidID DO
  2319.       IF (g.GetDisplayInfoData(NIL,displayInfo,SIZE(displayInfo),g.dtagDisp,dispID) > 0) &
  2320.          (displayInfo.notAvailable = 0) &
  2321.          (LONGSET{g.isHAM,g.isExtraHalfBrite,g.isDualPF} * displayInfo.propertyFlags = LONGSET{}) &
  2322.          (g.GetDisplayInfoData(NIL,nameInfo,SIZE(nameInfo),g.dtagName,dispID) > 0)
  2323.       THEN
  2324.         SYS.ALLOCATE(node);
  2325.         IF node # NIL THEN
  2326.           SYS.ALLOCATE(node.node.name);
  2327.           IF node.node.name # NIL THEN
  2328.             COPY(nameInfo.name,node.node.name^);
  2329.             node.displayID := dispID;
  2330.             e.AddTail(lvlist, node);
  2331.             IF dispID=displayID THEN firstindex := index END;
  2332.             INC(index);
  2333.           ELSE
  2334.             EXIT
  2335.           END;
  2336.         ELSE
  2337.           EXIT
  2338.         END;
  2339.       END;
  2340.       dispID := g.NextDisplayInfo(dispID);
  2341.     END;
  2342.  
  2343.     ng.leftEdge := 16;
  2344.     ng.topEdge := txH+8+topborder;
  2345.     ng.width := width-25;
  2346.     ng.height := txH*6+15;
  2347.     ng.gadgetText := LocStr(MSGCHOOSESM);
  2348.     ng.gadgetID := gadLISTVIEW;
  2349.     ng.flags := LONGSET{gt.highLabel,gt.placeTextAbove};
  2350.  
  2351.     IF firstindex >= 0 THEN lvSelectedTag := gt.lvSelected
  2352.                        ELSE lvSelectedTag := u.ignore END;
  2353.  
  2354.     gad := gt.CreateGadget(gt.listViewKind, gad, ng,
  2355.                     gt.lvLabels,       SYS.ADR(lvlist),
  2356.                     gt.lvShowSelected, NIL,
  2357.                     gt.lvScrollWidth,  txW*2,
  2358.                     I.layoutaSpacing,  2,
  2359.                     lvSelectedTag,     firstindex,
  2360.                     u.done);
  2361.     IF gad = NIL THEN EXIT END;
  2362.  
  2363.     Win := I.OpenWindowTagsA(NIL,
  2364.                              I.waLeft,        30,
  2365.                              I.waTop,         20,
  2366.                              I.waInnerWidth,  width,
  2367.                              I.waInnerHeight, height,
  2368.                              I.waTitle,       SYS.ADR(MuchText),
  2369.                              I.waFlags,       LONGSET{I.activate,I.windowDrag,I.windowDepth,I.simpleRefresh,I.rmbTrap},
  2370.                              I.waIDCMP,       gt.listViewIDCMP+gt.buttonIDCMP+LONGSET{I.gadgetUp,I.refreshWindow},
  2371.                              I.waPubScreen,   pub,
  2372.                              I.waGadgets,     glist,
  2373.                              u.done);
  2374.     IF Win = NIL THEN EXIT END;
  2375.     gt.RefreshWindow(Win, NIL);
  2376.  
  2377.     dispID := displayID;
  2378.     terminated := f;
  2379.  
  2380.     WHILE ~terminated DO
  2381.       e.WaitPort(Win.userPort);
  2382.       LOOP
  2383.         IF terminated THEN EXIT END;
  2384.         imsg := gt.GetIMsg(Win.userPort);
  2385.         IF imsg=NIL THEN EXIT END;
  2386.         gad := imsg.iAddress;
  2387.   
  2388.         IF I.gadgetUp IN imsg.class THEN
  2389.           CASE gad.gadgetID OF
  2390.           | gadBUTTONSave:   result := 1; displayID := dispID; terminated := w;
  2391.           | gadBUTTONUse:    result := 2; displayID := dispID; terminated := w;
  2392.           | gadBUTTONCancel: terminated := w;
  2393.           | gadLISTVIEW:     node := GetNode(lvlist,imsg.code);
  2394.                              IF node # NIL THEN dispID := node.displayID END;
  2395.           ELSE
  2396.           END;
  2397.         END;
  2398.  
  2399.         IF I.refreshWindow IN imsg.class THEN
  2400.           gt.BeginRefresh(Win);
  2401.           gt.EndRefresh(Win, I.LTRUE);
  2402.         END;
  2403.  
  2404.         gt.ReplyIMsg(imsg);
  2405.   
  2406.       END;
  2407.     END;
  2408.  
  2409.     EXIT
  2410.   END;
  2411.  
  2412.   IF Win   # NIL THEN I.CloseWindow(Win) END;
  2413.   IF glist # NIL THEN gt.FreeGadgets(glist) END;
  2414.   IF vi    # NIL THEN gt.FreeVisualInfo(vi) END;
  2415.   IF pub   # NIL THEN I.UnlockPubScreen(NIL,pub) END;
  2416.  
  2417.   RETURN result;
  2418. END ScreenModeReq;
  2419.  
  2420.  
  2421. (*-------------------------------------------------------------------------*)
  2422.  
  2423.  
  2424. PROCEDURE SavePrefs;
  2425.  
  2426.   PROCEDURE SavePrefsName(name: StringPtr);
  2427.   VAR file: d.FileHandlePtr;
  2428.       l: LONGINT;
  2429.   BEGIN
  2430.     file := d.Open(name^,d.newFile);
  2431.     IF file # NIL THEN
  2432.       SYS.SETREG(0,d.Write(file,"FORM",4));
  2433.       l := 16;
  2434.       SYS.SETREG(0,d.Write(file,l,4));
  2435.       SYS.SETREG(0,d.Write(file,"MUMO",4));
  2436.       SYS.SETREG(0,d.Write(file,"DPID",4));
  2437.       l := 4;
  2438.       SYS.SETREG(0,d.Write(file,l,4));
  2439.       SYS.SETREG(0,d.Write(file,id,4));
  2440.       d.OldClose(file);
  2441.     END;
  2442.   END SavePrefsName;
  2443.  
  2444. BEGIN
  2445.   IF DirExists("ENV:") THEN
  2446.     SavePrefsName(SYS.ADR("ENV:MuchMore.prefs"))
  2447.   END;
  2448.   IF DirExists("ENVARC:") THEN
  2449.     SavePrefsName(SYS.ADR("ENVARC:MuchMore.prefs"))
  2450.   END;
  2451. END SavePrefs;
  2452.  
  2453.  
  2454. (*-------------------------------------------------------------------------*)
  2455.  
  2456.  
  2457. PROCEDURE LoadPrefs;
  2458.  
  2459. VAR file: d.FileHandlePtr;
  2460.     l,i,s: LONGINT;
  2461.     buf: ARRAY 80 OF CHAR;
  2462.     ok: BOOLEAN;
  2463.  
  2464. BEGIN
  2465.   file := NIL;
  2466.   IF DirExists("PROGDIR:") THEN
  2467.     file := d.Open("PROGDIR:MuchMore.prefs",d.oldFile);
  2468.   END;
  2469.   IF (file=NIL) & DirExists("ENV:") THEN
  2470.     file := d.Open("ENV:MuchMore.prefs",d.oldFile);
  2471.   END;
  2472.   IF file # NIL THEN
  2473.     LOOP
  2474.       IF (d.Read(file,i,4) <= 0)        OR
  2475.          (i # SYS.VAL(LONGINT,"FORM"))  OR
  2476.          (d.Read(file,s,4) <= 0)        OR
  2477.          (d.Read(file,i,4) <= 0)        OR
  2478.          (i # SYS.VAL(LONGINT,"MUMO"))    THEN EXIT END;
  2479.       WHILE w DO
  2480.         IF (d.Read(file,i,4) <= 0)      OR
  2481.            (d.Read(file,s,4) <= 0)        THEN EXIT END;
  2482.         IF ODD(s) THEN INC(s) END;
  2483.         IF (s=4) & (i=SYS.VAL(LONGINT,"DPID")) THEN
  2484.           SYS.SETREG(0,d.Read(file,id,4));
  2485.         ELSE
  2486.           IF s < 0 THEN EXIT END;
  2487.           SYS.SETREG(0,d.Seek(file,s,d.current));
  2488.         END;
  2489.       END;
  2490.  
  2491.       EXIT;
  2492.     END;
  2493.     d.OldClose(file);
  2494.   END;
  2495.   IF (d.GetVar("EDITOR",buf,SIZE(buf),LONGSET{})>0) THEN
  2496.     COPY(buf,editcmd);
  2497.   END;
  2498. END LoadPrefs;
  2499.  
  2500.  
  2501. (*------------------------  Get Tooltypes:  --------------------------*)
  2502.  
  2503.  
  2504. PROCEDURE ParseIcon(icon: DiskObjectPtr);
  2505. VAR tt: StringPtr;
  2506.  
  2507. BEGIN
  2508.   IF icon # NIL THEN
  2509.     tt := FindToolType(icon.toolTypes,"PALETTE");    IF (tt # NIL) THEN COPY(tt^,Pens) END;
  2510.     tt := FindToolType(icon.toolTypes,"EXTRASPACE"); IF (tt # NIL) THEN spacing := SHORT(StrToInt(tt,10)) END;
  2511.     tt := FindToolType(icon.toolTypes,"FONT");       IF (tt # NIL) THEN COPY(tt^,FontName) END;
  2512.     tt := FindToolType(icon.toolTypes,"EDITOR");     IF (tt # NIL) THEN COPY(tt^,editcmd) END;
  2513.     tt := FindToolType(icon.toolTypes,"OLDSTYLE");   IF (tt # NIL) THEN oldstyle := (MatchToolValue(tt^,"TRUE")) END;
  2514.     tt := FindToolType(icon.toolTypes,"FASTQUIT");   IF (tt # NIL) THEN fastquit := (MatchToolValue(tt^,"TRUE")) END;
  2515.     tt := FindToolType(icon.toolTypes,"INTERLEAVED");IF (tt # NIL) THEN interleaved := (MatchToolValue(tt^,"TRUE")) END;
  2516.     tt := FindToolType(icon.toolTypes,"PLANES");     IF (tt # NIL) THEN depth := SHORT(StrToInt(tt,10)) END;
  2517.     tt := FindToolType(icon.toolTypes,"TABWIDTH");   IF (tt # NIL) THEN tabw := SHORT(StrToInt(tt,10)) END;
  2518.     tt := FindToolType(icon.toolTypes,"PUBSCREEN");  IF (tt # NIL) THEN COPY(tt^,pubscreenname) END;
  2519.     tt := FindToolType(icon.toolTypes,"TOOLPRI");    IF (tt # NIL) THEN taskpri := SHORT(SHORT(StrToInt(tt,10))) END;
  2520.     tt := FindToolType(icon.toolTypes,"SCROLLMODE"); IF (tt # NIL) THEN scrollmode := SHORT(StrToInt(tt,10)) END;
  2521.     tt := FindToolType(icon.toolTypes,"LEFT");       IF (tt # NIL) THEN left  := SHORT(StrToInt(tt,10)) END;
  2522.     tt := FindToolType(icon.toolTypes,"TOP");        IF (tt # NIL) THEN top   := SHORT(StrToInt(tt,10)) END;
  2523.     tt := FindToolType(icon.toolTypes,"WIDTH");      IF (tt # NIL) THEN width := SHORT(StrToInt(tt,10)) END;
  2524.     tt := FindToolType(icon.toolTypes,"HEIGHT");     IF (tt # NIL) THEN height:= SHORT(StrToInt(tt,10)) END;
  2525.     tt := FindToolType(icon.toolTypes,"WINDOW");     IF (tt # NIL) THEN win := (MatchToolValue(tt^,"TRUE")) END;
  2526.     FreeDiskObject(icon);
  2527.   END;
  2528. END ParseIcon;
  2529.  
  2530.  
  2531. (*------------------------------  MAIN:  ----------------------------------*)
  2532.  
  2533. BEGIN
  2534.  
  2535. (*------  Init:  ------*)
  2536.  
  2537.   mySigBit := -1;
  2538.   Me := SYS.VAL(d.ProcessPtr,ol.Me);
  2539.   meInt := SYS.VAL(LONGINT,Me);
  2540.   OldDir := Me.currentDir;
  2541.   oldpri := Me.task.node.pri; taskpri := oldpri;
  2542.   WriteName := "PRT:";
  2543.   MemIndex := ChunkSize;
  2544.   Sync := w;
  2545.   FontSize := 8;
  2546.   Pattern := "~(#?.info)";
  2547.   editcmd := 'C:Ed';
  2548.   id := g.invalidID;
  2549.   tabw := 8;
  2550.   depth := 2;
  2551.   left   := 0;
  2552.   top    := 0;
  2553.   width  := 640;
  2554.   height := 200;
  2555.   scrollmode := 1;
  2556.  
  2557.  
  2558.   IF (I.base.libNode.version < 37) OR (g.base.libNode.version < 37) THEN
  2559.     HALT(d.fail);
  2560.   END;
  2561.  
  2562.  
  2563.   mySigBit := e.AllocSignal(-1);
  2564.   IF mySigBit<0 THEN HALT(d.fail) END;
  2565.   mySig := LONGSET{mySigBit};
  2566.  
  2567.   iconBase     := e.OpenLibrary("icon.library",0);
  2568.   diskFontBase := e.OpenLibrary("diskfont.library",0);
  2569.  
  2570.  
  2571.   IF loc.base # NIL THEN
  2572.     catalog := loc.OpenCatalog(NIL,"muchmore.catalog",u.end);
  2573.   END;
  2574.  
  2575.   ol.OutOfMemHandler := OutOfMemHandler;
  2576.  
  2577.   INCL(ol.MemReqs,e.public);
  2578.  
  2579.   ol.New(ShowStack,ShowStackSize);
  2580.   NEW(ShowTask);
  2581.   NEW(FileInfo);
  2582.   NEW(ievent);
  2583.   NEW(conreq);
  2584.   NEW(Buffer);
  2585.  
  2586.   INCL(ol.MemReqs,e.chip);
  2587.   NEW(busyPointer);
  2588.   e.CopyMem(TheBusyPointer,busyPointer^,SIZE(busyPointer^));
  2589.   EXCL(ol.MemReqs,e.chip);
  2590.  
  2591. (*------  Setup:  ------*)
  2592.  
  2593.   NEW(FirstLine);
  2594. (*FirstLine.size := 0;
  2595.   FirstLine.text[0] := 0X; *)
  2596.  
  2597. (*------  Start:  ------*)
  2598.  
  2599.   LoadPrefs;
  2600.  
  2601.   IF ol.wbStarted THEN
  2602.  
  2603.     wbm := ol.wbenchMsg;
  2604.     IF iconBase # NIL THEN
  2605.       j := SHORT(wbm.numArgs); IF j>2 THEN j := 2 END;
  2606.       FOR i := 0 TO j-1 DO
  2607.         SYS.SETREG(0,d.CurrentDir(wbm.argList[i].lock));
  2608.         nameptr := wbm.argList[i].name;
  2609.         icon := GetDiskObject(nameptr^);
  2610.         IF icon=NIL THEN
  2611.           IF d.base.lib.version >= 37 THEN
  2612.             SYS.SETREG(0,d.CurrentDir(d.GetProgramDir()));
  2613.             icon := GetDiskObject(nameptr^);
  2614.           END;
  2615.           IF icon=NIL THEN
  2616.             clock := d.Lock("C:",d.sharedLock);
  2617.             SYS.SETREG(0,d.CurrentDir(clock));
  2618.             icon := GetDiskObject(nameptr^);
  2619.           END;
  2620.         END;
  2621.         ParseIcon(icon);
  2622.       END;
  2623.     END; (* IF iconBase#NIL *)
  2624.  
  2625.     IF wbm.numArgs >= 2 THEN
  2626.       ArgPtr := wbm.argList^[1].name; Name := ArgPtr^;
  2627.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[1].lock));
  2628.     ELSE
  2629.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[0].lock));
  2630.       FileReq(Name)
  2631.     END;
  2632.     IF clock # NIL THEN d.UnLock(clock) END;
  2633.  
  2634.   ELSE (* CLI started *)
  2635.  
  2636.     stdin := (Me.cis # Me.cli.standardInput); (* Input redirected? *)
  2637.  
  2638.     IF iconBase # NIL THEN
  2639.       progdir := d.GetProgramDir();
  2640.       IF progdir = NIL THEN
  2641.         progdir := d.Lock("C:",d.sharedLock); cLocked := w;
  2642.       END;
  2643.       oldcd := d.CurrentDir(progdir);
  2644.       IF d.GetProgramName(Name,LEN(Name)) THEN
  2645.         nameptr := d.FilePart(Name);
  2646.         icon := GetDiskObject(nameptr^);
  2647.         ParseIcon(icon);
  2648.         Name[0] := 0X;
  2649.       END;
  2650.       oldcd := d.CurrentDir(oldcd);
  2651.       IF cLocked THEN d.UnLock(progdir) END;
  2652.     END;
  2653.  
  2654.     rd := d.ReadArgs("B=PLANES/N/K,C=PALETTE/K,D=DISPMODEREQ/S,E=EDITOR/K,F=FONT/K,I=INTERLEAVED/S,O=OLDSTYLE/S,P=TOOLPRI/N/K,Q=FASTQUIT/S,S=SCROLLMODE/N/K,T=TABWIDTH/N/K,U=PUBSCREEN/K,X=EXTRASPACE/N/K,W=WINDOW/S,WL=LEFT/N/K,WT=TOP/N/K,WW=WIDTH/N/K,WH=HEIGHT/N/K,FILE",args,NIL);
  2655.     IF rd=NIL THEN
  2656.       SYS.SETREG(0,d.PrintFault(d.IoErr(),NIL));
  2657.       HALT(d.warn)
  2658.     END;
  2659.     IF args.b # NIL THEN depth := SHORT(args.b^) END;
  2660.     IF args.c # NIL THEN COPY(args.c^,Pens) END;
  2661.     IF args.d # NIL THEN modeReq := w END;
  2662.     IF args.e # NIL THEN COPY(args.e^,editcmd) END;
  2663.     IF args.f # NIL THEN COPY(args.f^,FontName) END;
  2664.     IF args.i # NIL THEN interleaved := w END;
  2665.     IF args.o # NIL THEN oldstyle := w END;
  2666.     IF args.q # NIL THEN fastquit := w END;
  2667.     IF args.p # NIL THEN taskpri := SHORT(SHORT(args.p^)) END;
  2668.     IF args.s # NIL THEN scrollmode := SHORT(args.s^) END;
  2669.     IF args.t # NIL THEN tabw := SHORT(args.t^) END;
  2670.     IF args.u # NIL THEN COPY(args.u^,pubscreenname) END;
  2671.     IF args.x # NIL THEN spacing := SHORT(args.x^) END;
  2672.     IF args.w # NIL THEN win := w END;
  2673.  
  2674.     IF args.wl # NIL THEN left  := SHORT(args.wl^) END;
  2675.     IF args.wt # NIL THEN top   := SHORT(args.wt^) END;
  2676.     IF args.ww # NIL THEN width := SHORT(args.ww^) END;
  2677.     IF args.wh # NIL THEN height:= SHORT(args.wh^) END;
  2678.  
  2679.     IF args.file # NIL THEN COPY(args.file^,Name); stdin := f END;
  2680.     d.FreeArgs(rd); rd := NIL;
  2681.   END;
  2682.  
  2683.   IF pubscreenname # "" THEN
  2684.     win := w;
  2685.   END;
  2686.  
  2687.   IF taskpri#oldpri THEN SYS.SETREG(0,e.SetTaskPri(Me,taskpri)) END;
  2688.  
  2689.   IF tabw < 1 THEN tabw := 1 END;
  2690.  
  2691.   IF depth < 1 THEN depth := 1 END;
  2692.   IF depth > 2 THEN depth := 2 END;
  2693.  
  2694.   IF str.Occurs(editcmd,"%s")<0 THEN str.Append(editcmd,' "%s"') END;
  2695.  
  2696.   IF FontName[0]#0X THEN
  2697.     i := 0;
  2698.     j := SHORT(str.Length(FontName));
  2699.     LOOP
  2700.       IF i >= j THEN EXIT END;
  2701.       IF FontName[i]='/' THEN
  2702.         FontName[i] := 0X;
  2703.         FontSize := SHORT(StrToInt(SYS.ADR(FontName[i+1]),10));
  2704.         j := i;
  2705.         EXIT
  2706.       END;
  2707.       INC(i);
  2708.     END;
  2709.     IF j<LEN(FontName)-6 THEN
  2710.       e.CopyMem(".font",FontName[j],6);
  2711.     END;
  2712.   END;
  2713.  
  2714.   IF Pens[0]#0X THEN
  2715.     ci := 0;
  2716.     chptr := SYS.ADR(Pens);
  2717.     Pens[LEN(Pens)-1] := 0X;
  2718.     LOOP
  2719.       Cols[ci] := SHORT(StrToInt(SYS.VAL(StringPtr,chptr),16));
  2720.       INC(ci); IF ci=4 THEN EXIT END;
  2721.       WHILE (chptr^#0X) & (chptr^#",") DO
  2722.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2723.       END;
  2724.       IF chptr^="," THEN
  2725.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2726.       ELSE
  2727.         EXIT
  2728.       END;
  2729.     END;
  2730.   END;
  2731.  
  2732.   IF FontSize>50 THEN FontSize := 50 END;
  2733.   IF FontSize< 5 THEN FontSize :=  5 END;
  2734.  
  2735.   IF spacing< 0 THEN spacing :=  0 END;
  2736.   IF spacing>20 THEN spacing := 20 END;
  2737.  
  2738.   IF width <150 THEN width  := 150 END;
  2739.   IF height< 70 THEN height :=  70 END;
  2740.  
  2741.   IF modeReq & (gt.base#NIL) THEN
  2742.     IF ScreenModeReq(id) = 1 THEN SavePrefs END;
  2743.   END;
  2744.  
  2745. (*------  Open File:  ------*)
  2746.  
  2747.   IF stdin THEN
  2748.     MyFile := d.Input();
  2749.     Name := "STDIN";
  2750.   ELSE
  2751.     LOOP
  2752.       MyFile := d.Open(Name,d.oldFile);
  2753.       IF MyFile#NIL THEN EXIT END;
  2754.       FileReq(Name)
  2755.     END;
  2756.   END;
  2757.  
  2758. (*-----  Open Display:  -----*)
  2759.  
  2760.   OpenDisplay;
  2761.  
  2762. (*------  Get KeyMap:  ------*)
  2763.  
  2764.   IF e.OpenDevice("console.device",-1,conreq,LONGSET{})#0 THEN HALT(d.fail) END;
  2765.   console := conreq.device;
  2766.   con.base := console;
  2767. (*ievent.nextEvent := NIL;
  2768.   ievent.qualifier := {};
  2769.   ievent.eventAddress := NIL; *)
  2770.   ievent.class := ie.rawkey;
  2771.  
  2772.   FOR i := 0 TO 3FH DO
  2773.     ievent.code := i;
  2774.     SYS.SETREG(0,con.RawKeyConvert(ievent,KeyMap[i],16,NIL));
  2775.   END;
  2776.  
  2777. (*------  Decrunch:  ------*)
  2778.  
  2779.   Decrunch;
  2780.  
  2781. (*------  Init & Add 2nd Task:  ------*)
  2782.  
  2783.   ShowTask.spLower := ShowStack;
  2784.   ShowTask.spUpper := SYS.VAL(e.APTR,SYS.VAL(LONGINT,ShowStack) + ShowStackSize);
  2785.   ShowTask.spReg   := ShowTask.spUpper;
  2786.   ShowTask.node.type := e.task;
  2787.   ShowTask.node.name := SYS.ADR("muchmore show task");
  2788.   ShowTask.node.pri  := Me.task.node.pri+1;
  2789.   (* $IF SmallData *)
  2790.   ShowTask.userData  := SYS.REG(13);           (* VarBase *)
  2791.   (* $END *)
  2792.  
  2793.   e.Forbid;
  2794.    e.AddTask(ShowTask,ShowProc,NIL);
  2795.    ShowTaskRunning := w;
  2796.   e.Permit;
  2797.  
  2798.   SYS.SETREG(0,e.Wait(mySig));
  2799.  
  2800.  
  2801. (*------  Main Load / Display Loop:  ------*)
  2802.  
  2803.   LOOP
  2804.     fg := 1; bg := 0; oldfg := fg; oldbg := bg; style := SHORTSET{};
  2805.     RQLen := -1; RQPos := -1;
  2806.     AnzLines := 1;
  2807.     LastLine := FirstLine;
  2808.     BottomLine := FirstLine;
  2809.     TopLine    := FirstLine;
  2810.     TextLength := 0;
  2811.     ReadLength := 0;
  2812.     FindLine   := NIL;
  2813.     FOR i := 0 TO 9 DO TextMarkers[i] := NIL END;
  2814.  
  2815.     FileLength := 0;
  2816.  
  2817.     IF ~stdin THEN
  2818.       MyLock := d.Lock(Name,d.sharedLock);
  2819.       IF MyLock # NIL THEN
  2820.         IF d.Examine(MyLock,FileInfo^) THEN FileLength := FileInfo.size END;
  2821.         d.UnLock(MyLock); MyLock := NIL;
  2822.         IF FileLength=0 THEN Request(LocStr(MSGEMPTY)^) END;
  2823.       END;
  2824.     END;
  2825.  
  2826.     (*------  Start displaying & Loading:  ------*)
  2827.  
  2828.     NewDisp := w;
  2829.  
  2830.     e.Signal(ShowTask,showSig);
  2831.  
  2832.     REPEAT
  2833.       LoadLine := GetTextLine();
  2834.       IF LoadLine=NIL THEN
  2835.         IF ~stdin THEN d.OldClose(MyFile) END;
  2836.         MyFile := NIL;
  2837.       ELSE
  2838.         LoadLine.prev := LastLine;
  2839.         LastLine.next := LoadLine;
  2840.         LastLine := LoadLine;
  2841.       END;
  2842.       IF SignalNewData THEN e.Signal(ShowTask,showSig) END;
  2843.     UNTIL (MyFile=NIL) OR Done OR NewText;
  2844.     IF SignalAllRead THEN e.Signal(ShowTask,showSig) END;
  2845.     REPEAT
  2846.       SYS.SETREG(0,e.Wait(mySig));
  2847.       IF print THEN
  2848.         in  := d.Open("NIL:",d.newFile);
  2849.         IF d.SystemTags(PStr,d.sysInput,    SYS.VAL(e.APTR,in),
  2850.                              d.sysOutput,   NIL,
  2851.                              d.sysAsynch,   d.DOSTRUE,
  2852.                              d.sysUserShell,d.DOSTRUE,
  2853.                              u.done)                   = -1 THEN
  2854.           d.OldClose(in);
  2855.         ELSE
  2856.           Decrunched := f; INC(meInt);
  2857.         END;
  2858.         in := NIL;
  2859.         print := f;
  2860.       END;
  2861.       IF save THEN
  2862.         in := d.Open(Name,d.oldFile);
  2863.         IF in=NIL THEN I.DisplayBeep(NIL) ELSE
  2864.           ol.New(buffer,savesize);
  2865.           SYS.SETREG(0,d.Seek(in,savefrom,0));
  2866.           IF d.Read(in,buffer^,savesize)#savesize THEN
  2867.             I.DisplayBeep(NIL);
  2868.             d.OldClose(in); in := NIL;
  2869.           ELSE
  2870.             d.OldClose(in); in := NIL;
  2871.             IF copy THEN
  2872.               iff := NIL;
  2873.               LOOP
  2874.                 IF ip.base=NIL THEN EXIT END;
  2875.                 iff := ip.AllocIFF();
  2876.                 IF iff=NIL THEN EXIT END;
  2877.                 iff.stream := SYS.VAL(LONGINT,ip.OpenClipboard(0));
  2878.                 IF iff.stream=NIL THEN EXIT END;
  2879.                 ip.InitIFFasClip (iff);
  2880.                 IF (ip.OpenIFF  (iff, ip.write) = 0) &
  2881.                    (ip.PushChunk(iff, SYS.VAL(LONGINT,"FTXT"), ip.idFORM, ip.sizeUnknown)=0) &
  2882.                    (ip.PushChunk(iff, 0, SYS.VAL(LONGINT,"CHRS"), ip.sizeUnknown)=0) &
  2883.                    (ip.WriteChunkBytes(iff,buffer^,savesize) = savesize) &
  2884.                    (ip.PopChunk (iff)=0) &
  2885.                    (ip.PopChunk (iff)=0) THEN
  2886.                 END;
  2887.                 EXIT;
  2888.               END;
  2889.               IF iff#NIL THEN
  2890.                 ip.CloseIFF(iff);
  2891.                 IF iff.stream#0 THEN ip.CloseClipboard (SYS.VAL(e.APTR,iff.stream)) END;
  2892.                 ip.FreeIFF (iff);
  2893.               END;
  2894.             ELSE
  2895.               out := d.Open(WriteName,d.newFile);
  2896.               IF out=NIL THEN I.DisplayBeep(NIL) ELSE
  2897.                 IF d.Write(out,buffer^,savesize)#savesize THEN I.DisplayBeep(NIL) END;
  2898.                 d.OldClose(out); out := NIL;
  2899.               END;
  2900.             END;
  2901.           END;
  2902.           DISPOSE(buffer);
  2903.         END;
  2904.         save := f;
  2905.       END;
  2906.       IF Done THEN EXIT END;
  2907.     UNTIL NewText;
  2908.     IF MyFile # NIL THEN
  2909.       IF ~stdin THEN d.OldClose(MyFile) END;
  2910.       MyFile := NIL
  2911.     END;
  2912.     IF Decrunched & d.DeleteFile(Name) THEN END;
  2913.     Decrunched := f;
  2914.     DisposeLines();
  2915.     FirstLine^.next := NIL; NewText := f;
  2916.     Name := OldName;
  2917.     stdin := FALSE;
  2918.     REPEAT
  2919.       FileReq(Name);
  2920.       MyFile := d.Open(Name,d.oldFile);
  2921.     UNTIL MyFile # NIL;
  2922.     Decrunch;
  2923.   END;   (* LOOP *)
  2924.  
  2925. CLOSE
  2926.  
  2927.   IF Window      # NIL THEN Window.userPort.sigTask := Me    END;
  2928.   IF ShowTaskRunning   THEN e.RemTask(ShowTask)              END;
  2929.   IF console     # NIL THEN e.CloseDevice(conreq)            END;
  2930.   IF Window      # NIL THEN I.CloseWindow(Window)            END;
  2931.   IF Screen      # NIL THEN I.OldCloseScreen(Screen)         END;
  2932.   IF MyFont      # NIL THEN g.CloseFont(MyFont)              END;
  2933.   IF (MyFile#NIL) & ~stdin THEN d.OldClose(MyFile)           END;
  2934.   IF in          # NIL THEN d.OldClose(in)                   END;
  2935.   IF out         # NIL THEN d.OldClose(out)                  END;
  2936.   IF Decrunched        THEN SYS.SETREG(0,d.DeleteFile(Name)) END;
  2937.   IF xpk         # NIL THEN e.CloseLibrary(xpk)              END;
  2938.   IF asl         # NIL THEN e.CloseLibrary(asl)              END;
  2939.   IF diskFontBase# NIL THEN e.CloseLibrary(diskFontBase)     END;
  2940.   IF iconBase    # NIL THEN e.CloseLibrary(iconBase)         END;
  2941.   IF mySigBit >= 0     THEN e.FreeSignal(mySigBit)           END;
  2942.   IF catalog     # NIL THEN loc.CloseCatalog(catalog);       END;
  2943.   IF taskpri # oldpri  THEN oldpri := e.SetTaskPri(Me,oldpri)END;
  2944.   OldDir := d.CurrentDir(OldDir);
  2945.  
  2946. END MuchMore.
  2947.  
  2948.